public class StringDemo { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub /*第一题:String str = new String("abc");创建了几个对象 第二题: String s="a"+"b"+"c"+"d"创建了几个对象(假设之前串池是空的) 第三题:StringBuilder sb = new StringBuilder(); String a = "a"; String b = "b"; String c = "c"; String d = "d"; String s = a+b+c+d; 这句话创建了几个对象 第四题:StringBuilder sb = new StringBuilder(); sb.append("a").append("b").append("c").append("d");这句话创建了几个对象*/ String str = new String("abc"); String s = "a" + "b" + "c" + "d"; //创建了几个对象(假设之前串池是空的) StringBuilder sb = new StringBuilder(); String a = "a"; String b = "b"; String c = "c"; String d = "d"; String s2 = a + b + c + d; StringBuilder sb2 = new StringBuilder(); sb2.append("a").append("b").append("c").append("d"); if(str instanceof Object){ System.out.println("str是对象"); }else{ System.out.println("str不是对象"); } System.out.println("-------------------------"); if(s instanceof Object){ System.out.println("s是对象"); }else{ System.out.println("s不是对象"); } System.out.println("-------------------------"); if(a instanceof Object){ System.out.println("a是对象"); }else{ System.out.println("a不是对象"); } if(sb instanceof Object){ System.out.println("sb是对象"); }else{ System.out.println("sb不是对象"); } } }