那要看情况
"abc"是一个常量字符串
如果这句话String a = new String("abc"); 之前,你已经用过“abc”的话,那么这句话直接引用那个常量,创建一个新的String对象,并把常量“abc”的内容拷贝到新分配的字符串空间
如果没有,那么首先要先创建并分配新的“abc”常量,然后进行相同的动作

解决方案 »

  1.   

    同意
    你看一下api里对这个构造函数的解释
    String(String) 
    分配一个新 String ,它和字符串参数中有相同的字符序列
      

  2.   

    是创建两个对象 String的机制是这样的:
    String str=new String("csdn");
    StringBuffer sb=new StringBuffer();
    sb.append(str);这是java类库String类标准运行程序。
      

  3.   

    我已经明白了, 谢谢.另外, 不明白的请参考:
    http://dev.csdn.net/develop/article/38/38155.shtm
      

  4.   

    String
    public String(String original)
    Initializes a newly created String object so that it represents the same sequence of characters as the argument; in other words, the newly created string is a copy of the argument string. Unless an explicit copy of original is needed, use of this constructor is unnecessary since Strings are immutable. Parameters:
    original - a String.
      

  5.   

    语句String a=new String("abc");的执行过程如下: 系统首先检查内存常量区中是否存在常量字符串"abc", 如果不存在,则在常量区中创建此字符串对象, 如果已经存在, 则不再在常量区中创建.然后, 构造方法String(String obj)直接引用常量区中的"abc"常量,创建一个新的String对象,并把常量“abc”的内容拷贝到新分配的字符串空间.这样一来, 此语句可能创建一个对象也可能创建两个对象.如果语句String a="abc";的后面
    接着有String a=new String("abc");
    那么执行String a=new String("abc")这条时, 只创建一个对象.
      

  6.   

    语句String a=new String("abc");的执行过程如下: 系统首先检查内存常量区中是否存在常量字符串"abc", 如果不存在,则在常量区中创建此字符串对象, 如果已经存在, 则不再在常量区中创建.然后, 构造方法String(String obj)直接引用常量区中的"abc"常量,创建一个新的String对象,并把常量“abc”的内容拷贝到新分配的字符串空间.这样一来, 此语句可能创建一个对象也可能创建两个对象.如果语句String a="abc";的后面
    接着有String a=new String("abc");
    那么执行String a=new String("abc")这条时, 只创建一个对象.对不对啊?
      

  7.   

    String 讨论的太多了,是2个对象,其中一个引用对象不用讨论太深了,意义不大
      

  8.   

    还是自己看代码吧JDK5:    /**
         * Initializes a newly created <code>String</code> object so that it
         * represents the same sequence of characters as the argument; in other
         * words, the newly created string is a copy of the argument string. Unless 
         * an explicit copy of <code>original</code> is needed, use of this 
         * constructor is unnecessary since Strings are immutable. 
         *
         * @param   original   a <code>String</code>.
         */
        public String(String original) {
    int size = original.count;
    char[] originalValue = original.value;
    char[] v;
       if (originalValue.length > size) {
          // The array representing the String is bigger than the new
          // String itself.  Perhaps this constructor is being called
          // in order to trim the baggage, so make a copy of the array.
        v = new char[size];
          System.arraycopy(originalValue, original.offset, v, 0, size);
      } else {
          // The array representing the String is the same
          // size as the String, so no point in making a copy.
        v = originalValue;
      }
    this.offset = 0;
    this.count = size;
    this.value = v;
        }
      

  9.   

    只有用new关键字才能创建对象,所以只有一个
      

  10.   

    创建了两个对象 
    String a = new String("abc");"abc" 
     a
      

  11.   

    这个要看上下文如果"abc"以前没用过,则创建两个String对像
    String a = new String("abc"); 
    a = new String(...) 一个
    "abc" JVM一查共享字串表,还没用过,按虚拟机规范,JVM创建一个"abc"的String,并返回它的堆地址如果"abc"用过,则只创建一个a = new String(...)对像,而"abc"这样的常量字符是共享的,JVM直接返回已创建的“abc”的String实例的堆地址。
    程序代码中的每一个"..."这样的常量字符,运行时都对应了一个String实例,这一点大家可以从以下代码中说明:int l = "abc".length()JDK的String.java中也注明了这一点
      

  12.   

    这是一个关于引用类型的问题,String a = new String("abc"); 将阿封装成一个引用类型的量,这个时候a是引用类型,它里面的元素也是引用类型,所以它的元素才指向abc。a没有直接指向abc!
      

  13.   

    书上写的那么清楚,对象创建必须用new才能产生,为什么你们那么多人都说是两个对象呢?
    "abc"就是一个字符数组char类型的常量,java8种基本类型中的一种。
      

  14.   

    String类是用final修饰的,"abc"如果以前没用过也会生成一个String对象。
    例:String a=String.valueOf(123);
    a=a+5;//这时候a的地址和第一次已经不一样了,a已经又是一个新对象了。
      

  15.   

    'a'才是char类型常量,不要搞错了"abc"是字符串。
      

  16.   

    感谢大家参与讨论,现在结贴。  根据大家的观点,另外我本人也参考了其它论坛,现在得结论如下:  语句String a=new new String("abc")在执行时,可能创建一个对象也可能两个对象,取决于
    共享常量区中是否存在"abc"字符串常量。     fast_time(fast_time) , catblue(limiaomiao), huqingmiao(梦里不知身是蝶),HITZXL(编程要厚道),  QQSu35(kaka),binny(骑个破车看夕阳) ,fohoo(飞狐) 是正确的。     YOUTAO89(),( ) sunant(天使之泪)  QQSu35(kaka) , catblue(limiaomiao)
     sunant(天使之泪),lizhiwo_wo(lizhiwo_wo) 理解错误或没完全理解。