Skip to main content
Post Closed as "Duplicate" by gtgaxiola, Philipp Wendler, rgettman java
edited body
Source Link
NightShade
  • 296
  • 1
  • 2
  • 9

How many string objects does the following code snippet generate in the string pool at runtime:

public class Test { public static void main(String[] args) { String autumnstring = new String("abc"); System.out.println("abc" == "def"); } } 

Does the second line generate a string object for def? Or is it ignored due to compiler optimization?

How many string objects does the following code snippet generate in the string pool at runtime:

public class Test { public static void main(String[] args) { String autumn = new String("abc"); System.out.println("abc" == "def"); } } 

Does the second line generate a string object for def? Or is it ignored due to compiler optimization?

How many string objects does the following code snippet generate in the string pool at runtime:

public class Test { public static void main(String[] args) { String string = new String("abc"); System.out.println("abc" == "def"); } } 

Does the second line generate a string object for def? Or is it ignored due to compiler optimization?

Source Link
NightShade
  • 296
  • 1
  • 2
  • 9

Number of objects in string pool

How many string objects does the following code snippet generate in the string pool at runtime:

public class Test { public static void main(String[] args) { String autumn = new String("abc"); System.out.println("abc" == "def"); } } 

Does the second line generate a string object for def? Or is it ignored due to compiler optimization?