check if two strings are equal in java

Solutions on MaxInterview for check if two strings are equal in java by the best coders in the world

showing results for - "check if two strings are equal in java"
Giada
26 Jan 2017
1//This expression is true if str1 and str2 are equal, and false if they're not
2str1.equals(str2)
3
4//example use case:
5String location = "London";
6String destination = "London";
7if (location.equals(destination)) {
8	System.out.println("You have arrived!");
9}
Joey
06 Nov 2018
1System.out.println("hey".equals("hey")); //prints true
2
3/*
4	always use .equals() instead of ==,
5    because == does the compare the string content but
6    loosely where the string is stored in.
7*/
Alice
23 Nov 2020
1// compare two strings in java using String.equals() method in java
2public class EqualsMethodDemo
3{
4   public static void main(String[] args)
5   {
6      String str1 = new String("HelloWorld");
7      String str2 = new String("Flower");
8      String str3 = new String("Hello");
9      String str4 = new String("Hello");
10      String str5 = new String("hello");
11      // compare str1 != str2
12      System.out.println("Compare " + str1 + " and " + str2 + ": " + str1.equals(str2));
13      // compare str3 = str4
14      System.out.println("Compare " + str3 + " and " + str4 + ": " + str3.equals(str4));
15      // compare str4 != str5
16      System.out.println("Compare " + str4 + " and " + str5 + ": " + str4.equals(str5));
17      // compare str1 != str4
18      System.out.println("Compare " + str1 + " and " + str4 + ": " + str1.equals(str4));
19   }
20}
Fabian
30 Jul 2019
1String1.equals(String2)
Alexa
06 Jan 2019
1public class EqualsMethodDemo
2{
3   public static void main(String[] args)
4   {
5      String str1 = new String("HelloWorld");
6      String str2 = new String("Flower");
7      String str3 = new String("Hello");
8      String str4 = new String("Hello");
9      String str5 = new String("hello");
10      // compare str1 != str2
11      System.out.println("Compare " + str1 + " and " + str2 + ": " + str1.equals(str2));
12      // compare str3 = str4
13      System.out.println("Compare " + str3 + " and " + str4 + ": " + str3.equals(str4));
14      // compare str4 != str5
15      System.out.println("Compare " + str4 + " and " + str5 + ": " + str4.equals(str5));
16      // compare str1 != str4
17      System.out.println("Compare " + str1 + " and " + str4 + ": " + str1.equals(str4));
18   }
19}
queries leading to this page
can you use 3d 3d to compare strings in java how to know if string is the same javahow to write a compareto 28 29 method in javaif string in javacompare if two strings are equal javacompareto method in strings in javacompare native string in javacheck if strings are equal javahow to compare two string in javacompare strings in comparator javajava how to check if 2 strings are equalhow to check if string equal in javahow do strings compareif string equal to javacomapre strings in javastring java comparejava string 3d 3d stringif string 3d 3d 22 22string java comparetocheck if two string is equal in javahow to compare the string in javahow to compare multiple strings in javahow to compare two string java check if equal 3d 3d between 2 strings in javaequality in strings with javacompare two string in havahow to compare strings in ajvacompare values in strings javacompare if two strings are equal in javahow to check if a string is 3d 3d to a different stirng javastring comparison with 3d 3d javastring comparison in java using equalsjava if stringhow to compare strings in java using if statementshow to compare a variable to a string in javacompare string valuejava string comparasonjava check equality of stringscompare string values in javacompare in string javajava string comparehow to check whether string is the same in javahow tocheck if both strings are equal in javacompareto strings in javajava can you check if a string 27s address is equalcompareto string function in javajava check if 2 string are equalhow to compare two numeric strings in javahow to compare two strings in javasjava compare 2 stringhow will you compare string values in javaprogram to check if two strings are equal in javahow to check string value is equal to another value in javajava comparing stringsjava compare strings by valuecomapre string in javacompare strings equal in javajava compare 2 stirngshow to check if a string javaif i have the same stringcomparing strings if st javahow to compare string in java using iftesting string equality java 3d 3d com 2 stringshwo to comate strings in javahow do i compare strings in javaif string is javajava string comparison methodsjava compare two stringcheck equal strings javai need to use comparator to compare two string typeshow string compareto works in javacompaer strings in javaif string 3d 3d string javahow to compare two strings in javastring value comparison in javastring comparison in javahow to check if strings are equal in javacan i use 3d 3d to compare strings in javacomparison of string in javajava if statement equalscheck if substring equals string javajava if comparing stringswrite a program to compare two string in javacompare string in javacompare string using comcreate equal stringshow to check two strings are equal or not in javacompare string java with with part of stringhow does string comparison work in javacompare twostrings javajava compare 2 strings for equalitycompare is a string is the same as an other string javacan you compare two string in jhavajava to compare string equalityequals to compare stringscompare strring javacompare two strings are equal in javastring is equal javacheck if string equals javawhat is equals 28 29 method of comparing strings for if else in javahow to comapre string in javaif string statement java not equalhow to check if the two strings are same in javajavatuto to compare string equalityjava check if 2 strings are equal to other 2 stringscheck if a string equals javacan we compare two strings using 3d 3d in javareliable way to compare strings javacompare length of two strings javajava if string is a stringcheck two strings are equalcompare string in java comaprtorcompareto in javahow is strings compared in javacomparer 2 string javastring comparision javastring equals javacompare operator string javajava check if string is similarjava compareto method stringshow to check if two strings are not the same in javajava how to compare 2 strignsccopmaring string in javajava compare two stringshow to check if two strings are equal in javawrite an application that compares two strings that a user inputs from the command linecomparing two strings in java 8compare strings ajvahow to use compare to in javamatch if 2 strings are equal javahow to check string is same or not in javajava check if two string are equaljava comparator comparing stringstring values are compared using 27 3d 3d 27 not 27equals 28 29 27most reliable way to compare strings javacomapre two strings in javahow to check if a string or javahow to check words in string is same javajava string compare functionstring compareto in javacompare multiple strings in javajava if a string is equal do somethingcheck if string is the same javajava check if sting is samestring compare to javastring comparison oin javajava compare more than two stringscompare two strings2 string not campare in javahow to use compareto in javacomparing the strings in javacompare content of two stringcheck if 2 strings matchcomparestrings javaequality of strings in javacomparing two string javajava check if string is equalsequality string in if in java how to compare two string javato compare two stringscomparing 2 strings in javajava how to compare 2 stringsequate strings javajava check if strings are similarsee if strings equal in javacompare strings 5b 5dcompare two stringa in jvcompare tow string in javajava language check if two strings are equalcompare different string java compareto java stringscompare three strings javacompare string in java if conditioncheck if 2 strings are identical javacheck whether two string are equal javaif statement string equal javacheck equal strings in javahow to comapre two strings in javacompareto java stringshow to compare 2 strings in javacomparing to string in javastring compare javahow to compare string values in javahow to compare strings values in javajava string comparison 27compare strings javqcompare string in jvastrings compare javacheck if string equeals stringcompare str javajava compare textcheck if two strings are equalcheck string equal in javahow does java compares stringshow to compare characters in a string in javacompare strings jaacompareto method in javajava check values of two strings are equaljava compare strings use 3d 3djava checking stingif else string comparison in javahow to compare string in if using javajava compre two stringscomparing two string in javacomparing strings content javaequals compare stringhow to check if string is not equal in javahwot to compare to strings javajava compareto stringsjava how to check if two strings are equalcompare strig in javacompare two strings in java ifjava compare two string equalcompare strings in if statement javajava compare strings equalhow to compare if two strings are equal in javacompare stringsjava code for comparing string in datahow ot do string comparison in javacomparison between two stringsstring 3d 3d in javacompare strings jaavcompare method for string javamatch two strings in javahow to compare content of string in javacompare strings with 3d 3d javacompare 2 strings in javacompare teo string in javacan you compare three strings in javajava compare differeces between two stringscompare string content javahow to check string is not equal in javacheck if string equal to string javacompare string valuesstring compareto method in javaif string is equal to javacheck string equality javadetermine if string in javacheck to strings in javacheck value of 2 strings javasee if two strings are equal javastring compare method in javahow to check if both strings have same letter in javastring compare to function javacompare two strings if they are equal javastrings comapreto javahow do you compare two strings in javacompare two strings jacajava compare to stringshow to compare two strings in java using comparatorjava check if two strings are the samecan we use 3d 3d to compare strings in javajava check if its a stringstring comparison in javsting comparison in javajava check if string is equal to another stringcompare string to string 5b 5dchecking whether two string are same or not in javahow to use string compare in javacomapre two string javahow to compare two strings in if condition in javahow to compare two string objects in javastring1 equals 28string2 29 javacan you compare strings with 3d 3d javacompare twoo strings in javajava check if string 3d 3dstring comparison in java using 3d 3dstring 3d 3d string javahow to do string comparison in javabest way to compare strings in javacomparing string javajava compareable stringjava 8 compare stringsstring equals new stringjava two string 5b 5d comparsionjav chk stringjava same string 3d 3d operator java comparing stringsjava test if strings are equalhow to check stringjava string equalitytext equals method javajavav compare stringhow to test string in javacompare equality of two strings in java compareto java stringjava check if string is samemethod used to compare two strings in javacompare value of teo strings in javacompare two stringcompare 2 strings in jjavaif 28string 3d 3d 22 22 29 javacheck if two strings have same in javahow to compare two strings javawhy doesn 27t 3d 3d work to compare strings in javatwo string compare in javahow to compare strings in javscheck same string javahow to compare string literal in javacommpare two string in javastring compare methid javaequality of stringshow to compare 2 string in javacheck same data in string javacheck if an string is greater than 1 in javahow to compare to stringshow to compare strings in jqcompare two stirngs javahow to compare string in java eejava test if 2 strings equalhow to check if two string are equal in javahow to check if an object equals a string in javacheck equality in javastring operations java comparing two stringscheck if 2 strings are equal javacompae stirng javacompare 2 string in java explainhow to check strings are equal in javahow to compare to strings in java 285 29 write a program to compare the strings given below 2c string 1 should be compared with all the other stringscompare string values javacompare chars in javahow to compare 2 stringhow to compare two strings if its matching or not in javahow to check two string are not equal in javacompare a part of string in javaequality string in javacompare to string in javado strings always need equals to compare in javajava string equal to stringbuilstring compare string javahow to check if a string is equals to another string in javacompareto in string javahow to check equality of two strings in javafunction to see if a strings content is equal to another strings contentcomparing strings with 3d 3d in javacompare a string with another string in javacheck if to strings are equal javastring compare in javacompare stings in javajava compare string valueshow to compare more than two string i javahow to check if string are equal in javajava check if stringhow to compare strings in jaawrite a program to compare the strings given below 2c string 1 should be compared with all the other stringshow to compare value of two strings in javahow to compare words from given string in javajava test string equalsjava string comparationjava check if two strings are differenthow to check if a string is equal to another string in javacompareto method java stringcomapre string javajava compare 2 stringsjava string compare tocompareig 2 string javacheck two string equal in javacomparison betwwen strings javacheck if two strings are equal in javahow to check if 2 strings are equal in javacheck if 2 string are eaqulstring compare 28 29 javacompareto java iof both string equal 3d 3d string in javacheck if same string in javastring compered javacompare a string in javawhich is the most reliable expression for testing where the value of two string variable are the same 3fcompare to in java stringsjava how to compare multiple strings at onfcecompareto in java stringcompare 2 string in javastr compare javahow to compare two given strings in javacheck two strings for equality in javaif two strings are equal javacomparing string with 3d 3d in javacheck if string is equal javachecking if strings are equal javaequals method to compare names in javamost reliable way to compare two strings javastring class compare javacomparing string new stirng 28 29 javacheck if strings are identical javacan you compare strings using 3code to compare strings in javacan 3d 3d be used to compare strings in javacompare 2 stringsjava check if strings are equalcompare strings in java not equaltwo string equal javacheck if strings are different javacan strings be compared with 3d 3d in javasame string not equal javacompareto string in javatest strings equal javajava compare stringshow does compareto work for strings in javacompare two strings in java using 3d 3dcheck if strings equal each otherjava string check if equalcreate a program that takes in two words 2c check for equality ignoring the cases 2c if the words are equal the print the word in java 3d 21 for string javahow to compare 2 strings in java for smallerin java 2c how should i compare two strings to see if they are equivalent 3fhow to compare strings in sjava compare in java stringcome 2 string in javacompare string and string object in javastrings compareto javasee if string is equal to given string in javacheck two strings are similar or notif string equalsjava comare stringsjava string equalstojava function compare two stringsjava compare stringehow to to check string 3d 3d in javacompare two strings in if statement java write a java program to compare two string y should nt we compare number in string javahow to check if string is same javajava compareto stringjava see if two strings are equaljava 2 streing ewqualjava if statement check for stringstring equal checker in javajava best way to compare stringscheck if string is one of javahow to check if 2 strings are equal or not in javajava check stringhow to compare string in javajava compare stringdequal 2 strings javahow to check string value in java 3fjava how does compareto workstring comparison using 3d 3d in javahow to check 2 strings are equal in java 3d 3d checks for java stringsjava string compareto methodcompare string 5b 5d javacan we compare strings in javawhich of the following are use to compare a string value 3fjava error equals 2 same stringsmost reliable way to check the two string are same values in javacomparing 2 stringshow to compare two strings in java which is greaterjava find out if a string is equal to anotherhow to compare string if javahow strings are compare in javacheck if string equalsstring values are compared using 27 21 3d 27 2c not 27equals 28 29 27how to check equality of string in javaset string compare javastring operators used to compare with stringcheck if 2 strings matches javaif with string javastring compare of datastring comparison methods in javacompare values of two strings in javajava check string equalshow to compare variable strings in javahow you compare two strings in javausing if to compare strings javacompare if two strings have same value javastring method to compare two stringscompare string with character javajava check if string equalshow to check if two strings are not equal in javahow to compare two strings in java using ifjava compare string equal or notjava method to compare two stringscompare to strings javacompare two string javahow compare two strings in javachecking if string equals string javahow to check both the string or equal or not in string in javahow to compare stringshow to check if strings have the same value in javastring 3d 3d string in javacan you compare strings with 3d 3d in javajava if equal string 3d 3d 3djava check strings for equalityhow to check if a string equals another string javahow to compare 2 strings javastringhow to compare each string of two strings if they are equals in javajava compare strinshow to compare two stringshow to compare string in java examplecompare two strings javacomparing strings using the methods equals 28 29 in javastring 2 strings are equal or nothow to comparte two tring in javato test two strings for equality you should use one of the two methodshow to comparer srings in javacheck if two stringsare equal javajava string equal checkhow to check if two strings are the same javahow to compare the two stringsjava use 21 3d compare stringcomparing strings in javahow to check if one string has the same values of another string javacheck equality of string javaque hace el metodo compare to javajava compare two strings similarityhow to compare the string value whether they are same or not in java check if string 3d string javahow to comapre strings 3e in javajava check if two strings are equalcheck for string equaity javacompare to function java stringcan i compare two strings in javajava comparing two stringscompare to string javajava string 21 3djava check strings equaljava compare strings of different sizewrite a program to check whether two strings are equal or not in javahow to check if string is equal to in javahow to check if string is in other javafastest way of compare strings javahow to compare stinrgs javastring compare in j vaacan you cmopare strings with 3ecompare 2 strings javacompare a string variable with a string in javahow ot compare string in javahow to compare two elements of a string iin java 3e in string comparison javastring is same javahow to compare two strings are equal in javastring compare to method javastring comparison in java using ifhow to check two strings are not same in javacomparing two string values in java less or moreto compare two string objects 3acheck if two string are equal javacompare two string in javahow oot compare string in javajava if compare stringswhy can 27t we compare string in java using 3d 3dhow to compair string values in stringjava check if string equals another stringjhow to compare 2 string in javajava if statement compare stringsstring compare function in javawhich is best for string comparison equals or 3d 3d in javahow to check the equality of string data member to another data member in javahow to compare data of string in javacompare to strings in javahow to check if two strings are identical in javacomparing string objectsstring comparison javajava check if string is equalcompare two string equal or not 2 25 java in stringjava same string valuecomparing two strings javacompare function for string in javadifference in strings valuestring comparision in javaif string 3d 3d java 7ecompare strings javahow to compare strings javajava how to compare string valuesstring compare in java 21 3d string javahow to compare two srings javatwo string are equal or not java methodjava string comparehow to comparison of java stringscheck if string is same javajava string compareto stringhow to compare a string in javahow to check string in javacompare of two string in javacompare string in jabastring coparison jkavaif comparsion for strings javacompare string java examplecomparing strings with 3d 3d javahow to comapre two string in javacompare 2 string javacheck two string if they equal in javahow to chcek string in javaif condition to compare two strings in javacompares strings in javajaba compare stirngcheck string equality in javacompare strings meaning javacheck if strings arent ewual javajava compareto with string compare 1 value of a string to each other value in the string javacomparing 2 string in javacompare strings in javacompare the two strings in javajava comparing stringhow compare a string in javacomparator java how to compare stringcompare tp strings javahow to check if the string is of same letters in javacheck two strings are equal in javamatching two strings codecompare two string equality in javacomparing string in javahow to check if a string is not equal in javahow to compare 2 strings 3fcompare two strings in java without case sensitivecomparing to strings in javacheck if two string are equal in javajava comparing strings using 3d 3dcomparing two strings in java with equals 2c compareto 2c 27 3d 3d 27how to compare class string to normal string in javacompare two stringsin java one statementjava compare method for stringscompare two strings with cosine similarity javajava comparing string valueshow do you compare strings in javacomparing two string 3d 3d javacomparing strings java2 strings compare javacompare 2 string are same in javahow to check string not equal in javajava if two strings are equalhow to check compare strings in javajava if string equals stringstr compare in javajava can i compare strings with 3d 3dhow to compare two string in javahow to compare the two strings in javacompare string in ajva compareto java stringcomparing two string variables in javahow to compare a variable with a string in javacompareto between strings javacompareto on string javacomparing 2 strings javastring comparing functions javaif string 3d string javacheck if strings are not equal javajava checking if two strings are equalhow to compare 2 string 3d 3d in javacode to compare two strings in javacamparing two stringshowing two strings equal in javahow to compare two strings in java in ordercompare two stirng in javachack string javajava compare sttringswhen compare string javajava if equal stringequalsto javacompare string deviation in javahow to compae two string in javahow to compare 2 strings in java for smallcheck equal string javajava checking string equalityhow to compare to string in javajava check if string equals another string or orjava if equalchecking equality of 2 strings in java compare string javajava string if equalshow to string compare in javacompare string javacompareable string javahow to compare data in strings javatest if two strings are equal javaevaluate 2 stringscomparing strings in java if statementhow to check equel between stringcompare string value in javahow to check if type of string in javastring to string test javacheck equality of two strings in javajava check if 2 strings are equaljava compare to stringhow to compare two strings in java 3fjava if string equalscheck 2 strings are equal in javaif string 5b2 5d 3d 3d 22 22how to compare strings in javamost accurate way to compare string in java 3d 3d in string comparison javajava check if string are not the samehow to compare two string variables in javajava compare stinghow to test if two strings are equal javacompare two strings in javahow to check if two strings are equal javahow to compare two strings in ajvacheck equality of string in javahow to test if a string equals another string in javajava string comparisonstring compare java javahow to compare values of string in javacompare elements of a string javacheck if string javacompare three strings in javausing string builder to compare 2 strings in javacompare substring in javajava compare if two strings are equalhow to check if strings are the same javajava string comparetohow to compare one string to another in javajava check if string 5b 5d is euqalhow to compare java stringsjava string comparison using 3d 3djava find if two strings are not equalcheck if string same javacan you compare 2 strings objects using 3ejava compare stringcompare fubction javacompare two string objects in javahow to check if string equals in javacompare strings in jjavacompare string using 3d 3dhow to compare string in jvawrite a program to compare two strings in javajava how to compare strings with compare methodjava string equals another stringcompareto string javacomparing two strigns in javacompare stringcomparing names in javacheck string equalitycompare text jastring comparison 3e in javajava best way to check if string is equalcomparing strings with string in javacomparing two strings in javacheck strings in javaif it is string how to check in javajava string in if comparecompare two strings in 5cjavahow to check if two string are equals in javafunction to check two string are same in javahow to compare a stringfunction compare between to string in javastring compareto method javacan you compare strings in javacompare string kavajava check for two equal stringshow to check if string is equal in javacheck if 2 strings are equal in javahow to check if twir string is samen in javajava string comparrisonhow to compare string values in jvahow to check 2c stringsame string how to campare to string in javahow to check two strings are equal in javacompareto method of string in javause compareto method for comparing two strings in java 5cjava strings compare equalcompareto by string javacompareto 28 29 string javaegality between strings javahow to check if string in javacompareto of string in javacompare function strings javacompare string is javacomparing of two strings in javacomare two string in javacompare 2 strings and print updated onejava string equals 1 or 2coparing strings javajava how to check if strings are the same valueequality string javacomapre strings javastring compareto in javacompare 2 strings java if statementmethod to compare two strings in javajava if check stringcomparing two stringsto compare two strings in javaor in java stringstring compare javac 2b 2bstring compareto string javacomparision of string in javahow can i check if a string is greate than another in javajava compare stirngsjava check two strings are equalcheck if 2 strings are not equal javajava check if is stringequals method to find if 2 strings are equalequating two strings in javahow to match string in javaequality if string in javajava string comparetostring comparion in javastring compare function javawhy we cannot compare strings in javahow we check two string are same or not in javajava test string equalityhow to check two string equal in javaif 2 string matchstrings comparision in javastring java ifcheck if two strings are the same javacompareto 28 29 java stringshow to check fi strings are same in javajava string compare valuehow to compare string in if condition in javajava if two string are equals lengthcompare strings and or operator in javajava compare string equalstring compare javawhat string not compare javacompare string function javajava comparing two words in a stringstring comapre in javahow to check equal string in javacomparing string object in javahow compare two string in javacheck if string equals string 5b 5d javacompare to stringin javaequals in javacompares two strings javahow java compare stringshoe to check if strings are same in javacheck if 2 strings are the same javaequal string in java in ifif srting javahow to compare string javahow to check whether 2 strings are equal in javacompare strings javajava how to compare to stringscompare string java 3d 3dstring compareto javastring equality javachecking string equality in javacompare char of string in javabest way to compare two strings in javajava compare two sets of stringsto compare string in javaif string and string are differentcheck to see if two strings resemble javahow to compare styring in javatest if strings are equal javajava how to compare stringsjava string comparisioncheck if two strings are equal javacompage string javahow to check if the value in a string variable and the string is same in javajava compare strinfhow to tell if two strings are equal javahow does compareto work in javahow to compare 2 strinhow to check if two strings are equalcheck if two strings are equal in java