13. String的常用方法-修改字符串 public String toLowerCase()
该方法将字符串中所有字符转换成小写,并返回转换后的新串。
public String toUpperCase()
该方法将字符串中所有字符转换成大写,并返回转换后的新串。
public String trim()
该方法去掉开头和结尾的空格,并返回得到的新字符串。值得注意的是,在原来字符串中间的空格并不去掉。
15. public class StringApp{
public static void main(String args[])
{
char str[]={'a','b','c','d'};
String str1=new String(str);
String s1="ABCD";
String s=new String(str1.concat(s1));
System.out.println("the length of s is:"+s.length());
System.out.println("a substring in s is:"+s.substring(2,5));
System.out.println("change into uppercase:"+s.toUpperCase());
String s2=s.replaceAll("abcd","ABCD");
System.out.println("use ABCD to replace:"+s2);
}
} 见源文件:StringApp.java
20. public class StringBufferApp
{
public static void main(String args[])
{
StringBuffer s=new StringBuffer("this is a test for StringBuffer");
s.setLength(14);
System.out.println(s);
s.setCharAt(0,'T');
s.append(" new");
s.insert(9," value");
System.out.println(s);
}
}
见源文件:StringBufferApp.java
StringBuffer类