StringBuffer s1=new StringBuffer("Hello World");System.out.println(s1.insert(3, "aa"));输出结果为Helaalo World。
举一反三
- StringBuffer s1=new StringBuffer('Hello World'); System.out.println(s1.append('Tom')); 输出结果为Hello WorldTom。
- 下列代码片段执行结果是: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);
- StringBuffer s = newStringBuffer("happynewyear");s1 = s.substring(5,8);System.out.println(s1);程序输出结果为() A: ynew B: new C: ewy D: happy
- 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