jacob deiter wrote:
String k="f";
is same as
String k=new String("f"); ??
jacob deiter wrote:
If that is the case ,if a class is declared as follow
Class A
{
String z="z";
String y="y";
String x="x";
}
It says that Class A contain three String Object?
Class A
{
Object z="z";
Object y="y";
Object x="x";
}
which one is best if I do not want any String operation like concatation,substr,...etc
No
Nitish Bangera wrote:String s = "x" creates string object at compile time
jacob deiter wrote:
No
please explain this
Nitish Bangera wrote:String s = "x" creates string object at compile time
SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
seetharaman venkatasamy wrote:.. two reference for the objects are placed in the string constant pool.
SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
doesn't mean String objects are created at compile time
SCJP 1.5(97%) My Blog
shivendra tripathi wrote:
doesn't mean String objects are created at compile time
If you are creating string as literal then certainly string object will be created at compile time. Please refer this http://www.javaranch.com/journal/200409/Journal200409.jsp#a1 for further clarification.
seetharaman venkatasamy wrote:
jacob deiter wrote:
No
please explain this
example,
when you say
there is only one object "abc" created in heap and two reference for the objects are placed in the string constant pool.
but here
there are 2 objects "abc" and "abc" are created in the heap though there are meaningfully same.
and s and t are pointing to the different object .
so always good practice is use String s = "abc" definition
Hope this helps![]()
Read Object#equals(), Object#hashCode(), String#equals() and String#hashCode(), which should explain why you get the same hash code.jacob deiter wrote:but the below code
. . .
return the same hash code value???
shaiksha vali wrote:What is mean by String Mutable and Immutable
SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]