切割用/r/n换行行吗
public class StringMethodDemo {
/**
* @param args
*/
public static void main(String[] args) {
// stringMethod4();
String str = " ab c ";
System.out.println("-"+str.trim()+"-");
String s = String.valueOf(4);
System.out.println(4+"");
System.out.println("ab"+"cd");
System.out.println("ab".concat("cd"));
}
private static void stringMethod4() {
String str = "lisi.wangwu.zhaoliu";
String[] strs = str.split("\\.");
for (int i = 0; i < strs.length; i++) {
System.out.println(strs[i]);
}
str = "hello";
String s = str.replace('a', 'k');
System.out.println("s="+s);
System.out.println(str);
}
private static void stringMethod3() {
String str = "aBCd";
String s = str.toLowerCase();
System.out.println(s);
String s1 = str.toUpperCase();
System.out.println(s1);
System.out.println(str);
char[] arr = str.toCharArray();
for(int x = 0; x<arr.length; x++){
System.out.println(arr[x]);
}
}
private static void stringMethod2() {
String str = "ThreadDemo.java";
System.out.println("contains(Demo):"+str.contains("Demo"));
System.out.println("starsWith(Thread):"+str.startsWith("Thread"));
System.out.println("endsWith(.java):"+str.endsWith(".java"));
System.out.println("isEmpty:"+str.isEmpty());
str = "abc";
System.out.println(str.equalsIgnoreCase("abC"));
}
private static void stringMethod() {
String str = "abcdaef";
System.out.println("length;"+str.length());
System.out.println("charAt(2):"+str.charAt(2));
System.out.println("indexOf(a):"+str.indexOf('a',2));
System.out.println("lastIndexOf(a):"+str.lastIndexOf('k'));
System.out.println("substring(1,3):"+str.substring(0,str.length()));
}
} |
|