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);
内容
- 0
class Test { public static void main(String[] args) { StringBuffer sb = new StringBuffer("hello world"); sb.replace(6, sb.length(), "java"); System.out.println( sb.toString() ); } } 选择正确的运行结果 A: hello javad B: hellojava C: hello java
- 1
StringBuffer s = newStringBuffer("happynewyear");s1 = s.substring(5,8);System.out.println(s1);程序输出结果为() A: ynew B: new C: ewy D: happy
- 2
调用以下类D和E的main() 方法的输出结果为?class D { public static void main(String[] args) { String s1 = new String("hello"); String s2 = new String("hello"); if (s1.equals(s2)) System.out.println("equal"); else System.out.println("not equal"); }} class E { public static void main(String[] args) { StringBuffer sb1 = new StringBuffer("hello"); StringBuffer sb2 = new StringBuffer("hello"); if (sb1.equals(sb2)) System.out.println("equal"); else System.out.println("not equal"); }} A: D: equal; E: equal B: D: not equal; E: not equal C: D: equal; E: not equal D: D: not equal; E: equal
- 3
已知定义字符串s,其格式为StringBuffer s=new StringBuffer(“hello”).若要朝s中尾部追加一串字符串,应调用StringBuffer类中的______________方法。
- 4
执行StringBuffer s = new StringBuffer("abc"); s.insert(1,"Good"); s的正确结果是()