Hi Sam, I'll see what I can do to clear things up a little with Strings. When javac compiles your code for you, it creates a literal pool which is basically a collection of all of the literal values that you have written in your program. Included in this literal pool are all of the Strings that you included in your program. So if you had the String "Hello World" in a line of code as it is here:
System.out.println("Hello World");
It would be a String object in a literal pool. If the following line of code were to execute:
String s1 = "Hello World";
Java recognizes this String object as one that it already contains in the literal pool and so it points s to that String object.
If, however, you were to write this instead:
String s2 = new String("Hello World");
Then Java does not use the pre-existing String object that it has in the literal pool. Instead it creates a new String object and s2 now points to that place in memory.
Whew! What a pile of stuff to remember. To sum it up a little bit: without using the new operator s1 will point to an existing String object so that:
a = "Hello World";
b = "Hello World";
a==b will evaluate to true (they are referencing the same String object in memory).
However,
a = new String("Hello World");
b = new String("Hello World");
a==b will evaluate to false because a and b are referencing separate String objects in memory)
(== with object references like a and b evaluates if their references are equal not the equality of the values of their objects).
Let me know if that was too much all at once. If so I could break it down for you or even give you a full example.
Hope that helped.
Paul