String的转换:
Example03.java:
public class Example03{
public void static main(String[] args){
String str = "absssss";
Char[] c = str.toCharArray();
for(int i = 0; i <= c.length -1 ; i ++ ){
if(i != c.length - 1 ) {
System.out.print(c[i] +",");
}else{
System.out.print(c[i]);
}
}
System.out.println(String.valueOf(11));
System.out.println(str.toUpperCase());
}
String的替换和去除空格操作:
public class Example05{
public void static main(String[] args){
String str = "itcast";
System.out.println(str.replace("it","cn.it");
String str1 = "i t c a s t "
System.out.println(str1.trim
);
System.out.println(str1.replace(" ","");
}
}
字符串的判断:
public class Example06{
public void static main(String[] args){
String s1 = "String";
String s2 = "Str";
System.out.println(s1.endsWith("ng"));
System.out.println(s1.startsWith("S"));
System.out.println(s1.contains("tri"));
System.out.println(s1.isEmpty());
System.out.println(s1.equals(s2));
}
}
字符串的截取和分割:
public class Example07{
public void static main(String[] args){
String s = "Peter-Morton-Ben";
System.out.println(s.substring(3));
System.out.println(s.substring(3,9));
String[] stringArray = s.split("-");
for(int i = 0; i < stringArray.length ; i ++){
if(i != (stringArray.length - 1)){
System.out.print(stringArray[i]+",");
}else{
System.out.print(stringArray[i]);
}
}
}
}