其它方法
No | 方法名称 | 类型 | 描述 |
---|---|---|---|
1 | public String concat(String str) | 普通 | 字符串连接,与"+"类似 |
2 | public String toLowerCase() | 普通 | 大写转小写 |
3 | public String toUpperCase() | 普通 | 小写转大写 |
4 | public String trim() | 普通 | 去掉字符串中左右两边的空格,中间空格保留 |
5 | public int length() | 普通 | 取字符串长度 |
6 | public String intern() | 普通 | 数据入池 |
7 | public boolean isEmpty | 普通 | 判断是否是空字符串(不是null, 而是"",长度0) |
范例:代码演示
public class StringOthers {
public static void main(String[] args) {
String str_1 = " hello ";
String str_2 = "World! ";
String str_3 = str_1.concat(str_2);
String str_4 = "";
String str_5 = "studenName";
System.out.println(str_3);
System.out.println(str_3.toUpperCase());
System.out.println(str_3.toLowerCase());
System.out.println("【" + str_3 + "】");
System.out.println("【" + str_3.trim() + "】");
System.out.println(str_3.length());
System.out.println(str_3.isEmpty());
System.out.println(str_4.isEmpty());
System.out.println(initCap(str_5));
}
public static String initCap(String temp){
return temp.substring(0,1).toUpperCase() + temp.substring(1);
}
}
代码结果
hello World!
HELLO WORLD!
hello world!
【 hello World! 】
【hello World!】
16
false
true
StudenName