字符操作
toCharArray:将字符串转换为字符数组
charAt:根据下标取出字符串中的响应字符
String s = "Helloyaay";
char[] chars = s.toCharArray();
for (char aChar : chars) {
System.out.println(aChar);
}
String s = "Helloyaay";
for (int i = 0; i < s.length(); i++) {
System.out.println(s.charAt(i));
}
其他:
substring(int start,int end);根据下标取字符串的值,含头不含尾
split(“,”)根据“,”分割字符串,返回的是字符数组
replace(“he”,“helll”);替换相应字符串。
startWith() 查找以什么开始的字符串
endWith() 查找以什么介绍的字符串
for(String name : s10){
//contains
if(name.indexOf("Demo")>0){
System.out.println(name);
}
}