Hi.
I have a question about string pool.
There is a code:
public static void main(String[] args) { String s1 = new String("ABC"); String s2 = new String("ABC"); String s3 = "ABC"; String s4 = "ABC"; final String s5 = "AB"; String s6 = "C"; System.out.println(s1 == s2); System.out.println(s2 == s3); System.out.println(s3 == s4); System.out.println(s4 == s5 + s6); System.out.println(s4 == s5 + "C"); }
General rules as I understand are that literals (like "ABC") go to String Poll, objects (like new String()) go to Java Heap.
In this way,
first println has "false"
2 - "false"
3 - "true"
4 - "false", because object plus literal goes Java Heap
5 - "true"
I have question for you about fifth println.
If I removed word final, I would get result false.
Why? How do strings behave in fifth line?
What exactly word final does?
As I know final variables go to something special memory space. For example global cache. I am not sure.
OK
Can you please explain me about fifth println with final and without final?
I will thankful for doc references, because I couldn't find anything.