"avc"本身就是一个对象
第一句是把s指向"avc"
第二句是新建了一个内容为"avc"的对象
一般建议使用第一种

解决方案 »

  1.   

    第二种用String对象"avc"创建新的String对象,比第一中多创建了一个对象,不推荐使用。
      

  2.   

    第二种创建新的String对象,再赋值,比第一中多创建了一个对象,会降低效率。
      

  3.   

    String s="avc";相当于char[] c={'a','v','c'}; String s=new String(c);
    这是java.lang.String里说的(version j2sdk 1.4.1_01)
    原文
     * <p><blockquote><pre>
     *     String str = "abc";
     * </pre></blockquote><p>
     * is equivalent to:
     * <p><blockquote><pre>
     *     char data[] = {'a', 'b', 'c'};
     *     String str = new String(data);
     * </pre></blockquote><p>
      

  4.   

    怎么会不一样啊,各位。
    第一种写法说到底只有“AVC”一个String,s只是一个引用而已
    第二种写法说到底也只有"ave"一个String,S也只是一个引用
    不知道你们说的第二种比第一种多创建一个对象在哪呢?
      

  5.   

    请问下面两句语句有何区别?
    String s="avc";               //建立一个String对象,将值"avc"付给它
    String s=new String("avc");   //建立一个String对象,再建立建立一个String对象将值付给第二个对象,然后将第二个对象的引用付给第一个对象,,,,,,,,
    第二种方法多产生了一个对象,多了一次赋值
      

  6.   

    /**
         * 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.
         *
         * @param   original   a <code>String</code>.
         */
        public String(String original) {
      this.count = original.count;
      if (original.value.length > this.count) {
          // 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.
          this.value = new char[this.count];
          System.arraycopy(original.value, original.offset,
           this.value, 0, this.count);
      } else {
          // The array representing the String is the same
          // size as the String, so no point in making a copy.
          this.value = original.value;
      }
        }