Pete Letkeman wrote:- Any time you create a string object using "new" you are creating a new object which does not get put into the string pool.
It is possible to call new String(...) without a String literal: String text = new String(somethingElse.toString()); in which case there would be nothing to go in the String pool. Though we all know that sort of code is pretty daft.
Liutauras Vilda wrote:. . . the string literal it contains - does. . . ..
earlier, I wrote:but 5 is incorrect. Reference variable would refer to an object in a heap, not string constant pool.
What String literal? The variable s doesn't point to a String literal in the original code, but to a String object representing “OCA”. The String literals go into the constant pools, yes, but not in the form of literals. A literal only exists in the source code and it is another way to represent a String object; only String objects exist in memory.
ethan crown wrote:. . . the reference variable (s) is pointing at its own String literal "OCA" in the normal heap. . . .