StringBuffer s1=new StringBuffer('Hello World');
System.out.println(s1.append('Tom'));
输出结果为Hello WorldTom。
System.out.println(s1.append('Tom'));
输出结果为Hello WorldTom。
举一反三
- StringBuffer s1=new StringBuffer("Hello World");System.out.println(s1.insert(3, "aa"));输出结果为Helaalo World。
- 下列代码片段执行结果是:String s=new String(”abc”); String s1=new String(s); if(s==s1){ System.out.println(”Hello”); } if(s.equals(s1)){ System.out.println(”World”); } A: Hello World B: Hello C: World D: Null
- 以下要输出“hello,world!”正确的是? A: String s=String.format("%1s%2s","hello","world");System.out.println(s); B: String s=String.format("%1$s,%2$s","hello","world");System.out.println(s); C: String s=String.format("%s,%s","hello","world");System.out.println(s); D: String s=String.format("%1s,%2s","hello","world");System.out.println(s);
- class Test { public static void main(String[] args) { StringBuffer sb = new StringBuffer("hello world"); sb.delete(6,sb.length()); System.out.println( sb.toString() ); } } A: Hello w B: Hello C: Hello worl
- 下列代码段执行后的结果是 StringBuffer s=new StringBuffer("Hello"); if((s.length()>=5)&&(s.append("there").equals("False"))) s.replace(0,6,"False"); System.out.println(s);