Determine if the strings to be compared are the same in Java

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

Determine if the strings to be compared are the same in Java
How to concatenate strings in java
Java reference to understand in the figure
How to get the date in java
Reason to add L to the number to be put in Java long type
Be careful if you find SHIFT-JIS in Java
CORBA seems to be removed in Java SE 11. .. ..
There seems to be no else-if in java
Import files of the same hierarchy in Java
What to do if the changes are not reflected in the jar manifest file
Pass the condition to be used in the Java8 lambda expression filter () as a parameter
[Java] How to omit the private constructor in Lombok
Source used to get the redirect source URL in Java
How to check if the characters entered in the Swift Text Field are email addresses
Java classes and instances to understand in the figure
If you want to recreate the instance in cloud9
[Java] What to do if the contents saved in the DB and the name of the enum are different in the enum that reflects the DB definition
I tried to implement the Euclidean algorithm in Java
Use a binary search to see if there are any values in the array
Memo that transitions to the login screen if you are not logged in with devise
How to get the class name / method name running in Java
I want to set the conditions to be displayed in collection_check_boxes
[Introduction to MVEL] Aiming to be the best MVELer in the world
How to connect the strings in the List separated by commas
Refer to C ++ in the Android Studio module (Java / kotlin)
[Android, Java] Convenient method to calculate the difference in days
Identify threads in the Java process that are wasting CPU
Create a method to return the tax rate in Java
Things to be aware of when writing code in Java
Several ways to concatenate strings separated by commas in Java
Implement the same function as C, C ++ system ("cls"); in Java
How to derive the last day of the month in Java
Differences in how to handle strings between Java and Perl
If variables are no longer highlighted in Eclipse's Java editor
How to switch Java in the OpenJDK era on Mac
[Rails] Where to be careful in the description of validation
I want to transition to the same screen in the saved state
If the submodule assets are not found in the Play Framework
What to do if the adb command cannot be executed
Be sure to compare the result of Java compareTo with 0
Check if Ethereum transactions are not included in the block
I want to simplify the conditional if-else statement in Java
Input to the Java console
[Java] I want to check that the elements in the list are null or empty [Collection Utils]
What to do when the changes in the Servlet are not reflected
If you want to include the parent class in Lombok's @builder
If you want to change the Java development environment from Eclipse
What to do if the Rails page doesn't appear in Rails tutorial 1.3.2
What to do if Cloud9 is full in the Rails tutorial
The milliseconds to set in /lib/calendars.properties of Java jre is UTC
Cast an array of Strings to a List of Integers in Java
[Java] I want to perform distinct with the key in the object
Sample code to call the Yahoo! Local Search API in Java
How to solve the unknown error when using slf4j in Java
The operator that was born to be born, instanceof (Java) ~ How to use the instanceof operator ~
What to do if you forget the root password in CentOS7
How to call multiple names at once in the same category
How to get the length of an audio file in java
How to increment the value of Map in one line in Java
I tried to solve the past 10 questions that should be solved after registering with AtCoder in Java
It should be the same as the sample when logging in to Twitter, but an error occurs ~ resolution