字符串
字符串的方法
| 方法 | 描述 |
|---|---|
| str.concat() | 将参数拼接到字符串上 |
| trim() | 去除字符串两端的字符串,不能去除中间 |
| replace(oldChar, newChar) | 将字符串的old参数替换为new参数 |
| length() | 返回此字符串的长度 |
| isEmpty() | 判断字符串是否为空 |
concat()方法
- 返回字符串类型
字符串在后面拼接
1
2
3String str = "床前明月光";
String str1 = str.concat("疑是地上霜。");
System.out.println(str1);trim()方法
1
2
3String str = " 床 前明 月光 ";
String str1 = str.trim();
System.out.println(str1);replace(oldChar, newChar)方法
1
2
3String str = "床前明月光";
String str1 = str.replace("床", "llll");
System.out.println(str1);length()方法
返回int类型
1
2
3String str = "床前明月光";
int str1 = str.length();
System.out.println(str1);isEmpty()方法
返回布尔类型
1
2
3String str = "床前明月光";
boolean str1 = str.isEmpty();
System.out.println(str1);
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 GGLSS!
评论
WalineValine








