您可以使用equals()method或compareTo()method比较两个字符串。
哪里,
equals()方法将此字符串与指定的对象进行比较。
compareTo()方法两个字符串按字典顺序进行比较。比较是基于字符串中每个字符的Unicode值。
这两种方法将给定的字符串分别与Case进行比较,即对不同大小写的String进行不同的处理。
下面的示例演示使用该equals()方法比较两个字符串。
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