Topic 1 - Variables and Data Types
Topic 2 - Conditionals and Strings
Topic 3 - Loops
Topic 4 - Arrays
Topic 5 - File Handling
Semester 1 Projects
Topic 6 - Classes/Objects and Methods
Topic 7 - ArrayLists
Semester Projects

Object Comparison

Presentation

Presentation LINK

Presentation Video


String Equality

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!)
}