0
Variable Declaration VS Object Creation
I don't Really understand when we can do String A = "Hello"; then why need String A = new String("Hello"); both seems to doing same thing to me ,,,, Please Explain me
3 Respostas
+ 1
Hope it helps..
https://www.sololearn.com/Discuss/3033964/?ref=app
edit: String in java is not primitive type.
0
From my understanding string, char, int, float, double, and boolean are primitive types in Java that do not require explicit instiantiation.
0
as you can see
a b are same object in memory,
but c not
String a = "Hello";
String b = "Hello";
String c = new String("Hello");
System.out.println(
System.identityHashCode( a) +"\n"+
System.identityHashCode( b) +"\n"+
System.identityHashCode( c)
);
also String is Object and all public objects can be created by new keywords