Summer 2010 15-110 (Reid-Miller) 24
Testing For Equality
• For primitive values use == for equality testing.
• For objects, use the equals method for testing
equal contents.
• The argument must be the same type as the object on which
equals() is called. The method returns true or false
depending on whether both objects are “equal” or not.
• For example, let day be an int variable and month
be a String variable.
! if (day == 1 && month.equals(“APRIL”)) {!
! System.out.println(“It’s April Fool’s Day”);!
}
Two String objects are equal if they have exactly the same
characters, including case and number of characters.