To compare strings, use the equals method, not the magnitude of the value.
String type variable A.equals(String type variable B)
Follow ".equals" to the String type variable, and specify the String type variable to be compared as it is in (). Since the content is "whether String type variable A and String type variable B are equal", true is returned if they are equal, and false is returned if they are not equal.
Sample code:
HelloWorld.java
public class HelloWorld{
public static void main(String []args){
String str1 = "abc";
String str2 = "Abc";
System.out.println(str1.equals(str2));
}
}
result:
$ javac HelloWorld.java
$ java HelloWorld
false
Recommended Posts