We still have one problem though, Strings are Objects! We can’t use == with Strings, it won’t give us the answer we’re looking for. You might say, wait, how are strings Objects? Well, you can do this:
String someName = "Edwin";
But you can also do:
String someName = new String("Edwin");
In the first example, Java creates a new Object for you and does what the second example shows, that is, the semantics are the same but the syntax is different. Both statements accomplish the same thing, that is, a new String object is created.
Huh. So how do you compare strings? With the equals() method in the String object.
String nituName = new String("Nitu");
String edwinName = new String("Edwin);
if (nituName.equals(edwinName))
{
System.out.println("They are the same!)
}