①.String 是不可变的,但StringBuffer是可以改变的!
②.g==g是当然是正确的,因为他们同一对象。A,C,D,F是不正确的因为f不是对象,E是错误的,因为d的值为4.2F,而g为4.2,所以返回false!

解决方案 »

  1.   

    如醉人说得String对象一经实例化就不能改变。而StringBuffer可以。
    equal比较的是两个句柄指向的是否是一个对象,所以只有2是对的。
      

  2.   

    1、String 类型是传值的StringBuffer 传引用,这点必须注意,一般人都认为两者都是传引用!
    2、若比较的是两个对象类型,则比较的是他们的引用, usxue(醉人)分析正确!C. d==f   D. d.equals(f)  F. g.equals(4.2); 好像是错误吧!简单类型不是对象!
      

  3.   

    那对于第一个改哪 儿才算是正确呀,这个我有点不明白了!这应该返回 return text;
      

  4.   

    dickensi()流星·逐日()  高手高手!
    照你的做果然可以看到变化了
    你能解释一下原因吗?
      

  5.   

    在第一题中,String是不可变的, 调用text.replace('j','l')函数返回一个新的String("lava"),并不会改变String text的值。 但是如果是text=text.replace('j','l'), text指向了新生成的String对象("lava").所以如果这时候 return text,    则返回的是"lava".第二题我想因为 Double 和 Float对象都没有 override equals()方法,所以等同于 == 操作符, 进行的是“浅”比较。 不象 Boolean对象, 重载了 equals()方法,改方法进行“深”比较。
      

  6.   

    They are all pass reference! (both String and StringBuffer)
    reference in StringReplace is changed. It is different from the outer one. Because String couldn't be modified after they are created. So the inner reference refer to a new String but the outer reference is still refer to the old String.StringBuffer is not the same situation:
    It could be modified. So all the reference will always refer to the same StringBuffer.