public class String6
{
public static void main ( String [] args )
{
String aName = "Mat";
String anotherName = "Mat";
if (aName.equals(anotherName))
System.out.println("the same");
String aName2 = "Mat";
if (aName2.equalsIgnoreCase("MAT"))
System.out.println("THE SAME");
String aName3 = "Mat";
int m = aName3.compareTo("Rob"); // m < 0
int n = aName3.compareTo("Mat"); // n == 0
int p = aName3.compareTo("Amy"); // p > 0
System.out.println( m + " " + n + " " + p );
String aName4 = "Mat";
String anotherName4 = "Mat";
if (aName4.equals(anotherName4))
System.out.println("Name's the same");
if (anotherName4.equals(aName4))
System.out.println("Name's the same");
if (aName4.equals("Mat"))
System.out.println("Name's the same");
}
}
Back to Lesson 11 Examples
Back to Java Main Page