Linked Questions
81 questions linked to/from What is Java String interning?
10 votes
2 answers
18k views
Difference between heap memory and string pool [duplicate]
What is the difference between heap memory and string pool in Java? in this link , it is said that: String s1 = "Hello"; String s2 = new String("Hello"); s1 points to String Pool's location and s2 ...
6 votes
3 answers
2k views
Difference between String intern method and normal string creation [duplicate]
I am not able to understand usage of intern method provider by String class. String s1 = "vivek"; //Stmt 1 String s2 = "vivek"; //Stmt 2 String s3 = s1.intern(); //Stmt 3 System.out.println(s1 == s2)...
4 votes
3 answers
2k views
Please explain intern() method functionality [duplicate]
Possible Duplicate: When should we use intern method of String? what is string interning? Please explain the inner workings of the following code: System.out.println(new String("ABC").intern()==...
3 votes
4 answers
195 views
String + int compare with same String + int in java? [duplicate]
Why i'm getting false in below statement. int x = 10; System.out.println("X="+x=="X="+x); //false If i'm right then after evaluation it will look like below statement.. System....
-1 votes
1 answer
469 views
what is Intern() in java? [duplicate]
public static void main(String[] args) { String literalstr = "ABC"; String literalstr2 = "ABC"; String str = new String("ABC"); String str2 = new String("ABC"); if (literalstr == ...
0 votes
1 answer
249 views
String reuse in Java [duplicate]
How does Java decide when a new String should be created? I assume it depends on the specific JVM implementation/ compiler, but I thought the results of this test were interesting enough to ask the ...
-3 votes
1 answer
231 views
Meaning of Interned String in JAVA [duplicate]
What is the meaning of interned strings in context of JAVA? What is the intern() method in String class? I recently came across a code where "test" == "test" //output- true The argument for the ...
0 votes
0 answers
189 views
How Java String Pool Working? [duplicate]
I am learning string implementations in java, got the following doubt while learning String s1 = "name1"; String s2 = "name1"; // both strings having same value; I know that, s1==s2 above ...
1 vote
2 answers
131 views
What is the difference between this two ways of initializing String [duplicate]
This two codes have defferent outputs and i don't know why. String a="abc"; String b="abc"; System.out.println(a==b + " " + a.equals(b)); The output is "true true" String a="abc"; String b=new ...
2 votes
0 answers
84 views
What does String intern() method do? [duplicate]
I read quite some answers about the String.intern() method but didn't quite get my answer. The intern method is a native method with the docs saying : Returns a canonical representation for the ...
1 vote
0 answers
78 views
How Java JDK create new Strings in String Pool [duplicate]
I have learned that when you have assigned the value with strings, it use a string pools. So that, they are using same address String S1 = “Hello World”; String S2 = “Hello World”; String S3 = “...
0 votes
0 answers
45 views
java String constants save heap memory? [duplicate]
Is having Java static final String (constants) will save heap space? Analyzing java heap dump of 1G showing up duplicate strings cost around 300M+ which means a lot for a app using max of 1G heap... ...
0 votes
0 answers
41 views
Java serialization String == and equals [duplicate]
I write an object to a file and then I read it. Then I make "if" to compare object's arguments. For example "genreDescription" is "Action". if (genreDescription == "Action" ) { System.out.println(...
-3 votes
2 answers
49 views
String Immutable in Java [duplicate]
I wanted to ask about String and Reference variable, String name = "John" String str= "John" In the video it says that it will refer to the value "John" instead of ...
798 votes
27 answers
852k views
What is the difference between == and equals() in Java?
I wanted to clarify if I understand this correctly: == is a reference comparison, i.e. both objects point to the same memory location .equals() evaluates to the comparison of values in the objects