length()
charAt(int index)
contains(String str)
toCharArray()
indexOf(String str)你m
- 作用:字符串第一次出现的位置
- 存在重载,两个参数的话可以指定从某个位置开始找
lastIndexOf(String str)
trim()
toUpperCase()
toLowerCase()
endWith(String str) startWith(str)
replace(char old, char new)
split()
- 对字符串进行拆分,该方法会返回拆分后的多个字符串
- 如果同时把空格和逗号都作为拆分的标志可以使用[],[]表选择
String[] arr=content.split("[ ,]");
String[] arr=content.split("[ ,]+");//+表示空格或逗号可以出现多个
compare()
- 比较大小(换言之字母在ascii表中的顺序)
- 两个字符串先比第一个,如果第一个不相等,不会继续比后面的字母,如果相等,则比第二个字母
- 特殊:如果
String a ="abc"
String b ="abcdef"
这种情况下用a比b就不是比的ASCII的顺序,而是比的字符串长度
本文章使用limfx的vscode插件快速发布