You can compare two strings using either equals() method or compareTo() method.
Where,
These two methods compare the given strings with respective to Case i.e. String with the different case are treated differently.
Following example demonstrates the comparison of two strings using the equals() method.
public class Sample{ public static void main(String args[]) { String str = "Hello World"; String anotherString = "hello world"; Object objStr = str; System.out.println( str.equals(anotherString) ); } }
false