1.借助jdk,选取几个String与StringBuffer、StringBuilder的常用API,并编写实例测试API的成功。
(1)String:
replace():替换
package xinshi;
public class hallo{
public static void main(String[] args){
String s1="123abc";
String s2=s1.replace('a','4');
System.out.println(s2);
}
}//结果:1234bc
toUpperCase():转换成大写字母
package xinshi;
public class hallo {
public static void main(String[] args) {
String s="string";
System.out.println(s. toUpperCase());
}
}
//结果:STRING
(2)StringBuffer:
reverse():字符串倒序
package xinshi;
public class hallo {
public static void main(String[] args) {
StringBuffer s=new StringBuffer("stringbuffer");
System.out.println(s. reverse());
}
}//