①.String 是不可变的,但StringBuffer是可以改变的!
②.g==g是当然是正确的,因为他们同一对象。A,C,D,F是不正确的因为f不是对象,E是错误的,因为d的值为4.2F,而g为4.2,所以返回false!
②.g==g是当然是正确的,因为他们同一对象。A,C,D,F是不正确的因为f不是对象,E是错误的,因为d的值为4.2F,而g为4.2,所以返回false!
equal比较的是两个句柄指向的是否是一个对象,所以只有2是对的。
2、若比较的是两个对象类型,则比较的是他们的引用, usxue(醉人)分析正确!C. d==f D. d.equals(f) F. g.equals(4.2); 好像是错误吧!简单类型不是对象!
照你的做果然可以看到变化了
你能解释一下原因吗?
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.