java compare two strings

Solutions on MaxInterview for java compare two strings by the best coders in the world

showing results for - "java compare two strings"
Emilia
22 May 2019
1String myStr1 = "Hello";
2String myStr2 = "Hello";
3String myStr3 = "Another String";
4System.out.println(myStr1.equals(myStr2)); // Returns true because they are equal
5System.out.println(myStr1.equals(myStr3)); // false
Alma
31 Feb 2017
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*/
Sebastián
10 Sep 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}
Matthias
07 Apr 2016
1******Java String compareTo()******
2
3  The Java String class compareTo() method compares the given 
4  string with the current string lexicographically. 
5  It returns a positive number, negative number, or 0.
6  ___________________________________________
7  	if s1 > s2, it returns positive number  
8	if s1 < s2, it returns negative number  
9	if s1 == s2, it returns 0  
10  ___________________________________________
11  
12  
Briley
16 May 2017
1if (aName.equals(anotherName))
2        { 
3            System.out.println(aName + " equals " + anotherName);
4        }
5        else 
6            { 
7                System.out.println(aName + " does not equal " +anotherName );
8                           
9            }
Elvina
29 Oct 2020
1// compare two strings in java .equals() method
2public class EqualOperatorDemo
3{
4   public static void main(String[] args)
5   {
6      String str1 = new String("helloworld");
7      String str2 = new String("helloworld");
8      System.out.println(str1 == str2);
9      System.out.println(str1.equals(str2));
10   }
11}
queries leading to this page
compare function strings javahow to compare 2 stringsjava compare 2 strings for equalityjavav compare stringcheck whether two strings are equal or not in javainbuilt function to compare two strings in javastring conparision in javacomparision of string in javajava string equal to stringhow to compare string literal in javacompare string function javahow to check if string equals in javajava how to compare stringsjava compare strings with errorsjava compare methodcompare two string javacompare two strings jacahow to check and compare in javajava string compare valuecompareto string method javacompareto string javay should nt we compare number in string javahow to compare 2 strings javastringcompare two strings in java using 3d 3dcompare 28 29 method in javastrcmp in javacompares two strings javajava how compare worksstring1 equals 28string2 29 javacomparing two strings in javathe string method compareto 28 29 returnshow to write a compareto 28 29 method in javacompare two string equality in javajava compareto in javacompareto 28 29 javajava check strings for equalityhow to compare strings in ajvacomapre string in javahow do you compare strings in java 3fjava compareable stringcompare two strings are equal in javacompare javahow to equal two strings in javawhat does compare method do in javacompare string in java comaprtorhow to compare two strings in ajvacompare string 5b 5d javacomparing two string in javacheck equality of string in javahow to compare 2 strings in java for smallercomparing 2 string in javacompareto by string javacomparing string equality javacheck if string equal in javacompareig 2 string javahow to check if strings are equal in javahow to compare the value of two strings in javacomapre two string javajava comparator comparing stringtest if strings are equal javacomparing 2 strings javahow oot compare string in javacomparing strings using the methods equals 28 29 in javahow to compare 2 strings in javajava compare a stringcheck if two strings are same in javastring values are compared using 27 3d 3d 27 2c not 27equals 28 29 27what can you compare with compare to in javahow to compare 2 strings 3fjava check if 2 strings are equal to other 2 stringscan you use 3d 3d to compare strings in javamatch two stringhow string comparison works in javacomparator java how to compare stringstring compare java 3d 3dcompare stringsequality of stringsthe to compare method javajava same string valuehwo to comate strings in javacompare the two strings in javajava string comparetocompare two strings in java without case sensitivejava string comparasonhow to check 2 strings are equal in javajava string compare to how it works 3d 3d in string comparison javastring comparison in java with referencejava if statement compare stringsjava compare strinfjava comparingwithcheck two strings are equal in javajava check if strings are equalcomparing 2 stringhow ot compare strinfs in javacheck if two strings are equal in javaare strings comparable in javawrite a java program to read two strings from command line argument and check the equality of two string using string function compare 2 stringscompare strings jaavcompareto of string in javajava comparing strings with 3d 3dcomapre two strings javajava comparing strnghow do i compare strings in javahow to use to compare method n javahow to compare strings in sjava java how to compare 2 strignsjava how to compare to stringshow to match string in javahow to check if two strings are not the same in javacomparing strings javastring value compare in javaexplain the compare function in javajava string compareto methodhow to compare tow strings in javacompare values in strings javacompare two stringsfastest way of compare strings javacompare strings javqhow to campare to string in javacompareto java stringtwo strings equal javajava 2 streing ewqualstring comare javacompare to string in javahow to compare two strings javacompare 2 string in javajava compare string valueshow to compare two strings in java which is greaterhow to check if a string is equal to another string in javahow to compare substring in javacompareto strings javaequals compare stringcomparing strings with string in javacompare 28 29 in javacheck if 2 strings matches javahow to compare the string value whether they are same or not in java string compareto java examplecompare two strings in if statement javahow to compare strings in javamatch two stringsstring compare methid javacompare string is javacomparing javahow to compare 2 string in javacompaer strings in javastring compareto in javacompare strings in java not equalequals string comparison javahow does compareto work for strings in javacompare twoo strings in javasame string compare stringcompare two strings using boolean function in javacompare string content javahow to compare stringto compare javastring compare javac 2b 2bcompare a string with another string in javacompare twostring in javacomparing strings content javacomaprinf two strings using boole an javaequality in strings with javahow to compare to stringscomparing string in jvamatching two strings codejava compare stringcomparison operator for string in javawhy we cannot compare strings in javajava comparatorstring compare function in javahow to check string value in java 3fjava string 21 3djava compare texthow to compare strings in jqjava test string equalsjava check values of two strings are equalhow to compare strings in jaajava check if string is equal to another stringcheck if 2 string are eaqulcompare multiple strings in javacompare to function java stringcomapre strings javaode to compare strings in javacompare 1 value of a string to each other value in the string javastring method to compare two stringscomparing strings in java if statementhow to string compare in javausing string with compare in javastring compareto javahow to compare with a 22 in javahow to compare two srings javaif with string javacompare method in java for two stringshow can i compare 2 strings in javacomparing two string 3d 3d javacompare two strings ljavajava 2 string comparehow to check equel between stringa compareto 28b 29 in javawrite a program to compare two string in javahow to write a compare method in javastring compare to javacompare to a javajavatuto to compare string equalitycompare string with equals javacompare in java stringchecking string equality in javawhen comparing strings in javacompare string valueshow to compare two given strings in javaif string 3d 3d string javacompare 2 strings javajava compare to stringcopmare strings javajava string comparison methodscompare to javahow to do string comparison in java 3d 3d com 2 stringshow to check if a string is 3d 3d to a different stirng javajava compareto method stringsif string 3d string javacomparing string object in javastring 1 3d 3d string 2how to comapre string in javahow to compare data in strings javajava two string equlaityjava comparing strings using 3d 3dhow you compare two strings in javajava compare scompare string in jvahow string compareto works in javacompareto java iof both string equaljava check if sting is samecheck for string equality javacompare two stirng in javahow to compare string in java eestring compareto method javacheck string equality in javajava compare stirngscompare is a string is the same as an other string javatwo string compare in javajava string comparisoncomparison two stringsjava compare stringscompare two stringjava string equalitystring comparision in javajava string compare 3d 3d checks for java stringscompare java stringjava compate stringshow to use compare to in javajava string compare functionjava if string is a stringstring value comparison in javacompare string using 3d 3dhow to comparison of java stringscompare two strings javaif string and string are differenthow to compare one string to another in javacomare two string in javacompareto between strings javafinal compare strings in javacompare value javajava how to compare string valueshow to check whether two strings are equal or not in javacreate 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 javajava checking stingif 2 string matchmethod to check string equalityjava comparetohow to check two strings are equal in java 2c compareto 28 29 2c in java stringcompare 2 strings in jjavahow to check if string equals in java in if statementcomparison of strings in javastring compare in java with equalshow to compare 2 strings javacompare sring values javahow to compare if two strings are equal in javahow to test string in javajava can you check if a string 27s address is equalin java 2c how should i compare two strings to see if they are equivalent 3fcompare 2 strings java if statementjava comparisoncompare 2 strings in javabest way to compare strings in javacompare two strings in java ifhow to compare two strings in java 3fsting comparison in javahow ot compare strings javahow to compare a variable with a string in javacompare two words in javato compare in javacompare if two strings are equal javahow to compare two elements of a string iin javahow to compare 2 strings in java for smallstring comaparitioni javastring comapre javastring and new string compare javacheck if string equal to string javause compareto method for comparing two strings in java 5cjava comparing stringstring comparison in java using equalscomparing two string javajavatuto compare two stringwhich of the following are use to compare a string value 3fcheck if strings arent ewual java equals 28 29 to compare stringshow to equal to stringhow to comparte two tring in javajhow to compare 2 string in javajava how to check if strings are the same valuejava sring comparecompare string in ajvacompareto in javahow to compare the string in javastring comparisonsjava string 3d 3d stringwhat does compareto do in javawhy we dont have string compare 28 29 javacompareto 28 29 java stringscompare javacompareto string in javacompare string java 3d 3djava compareto methodcompare between two strings in javacan you cmopare strings with 3ehow to check string in javaif 28str 5bi 5d compareto 28str 5bj 5d 29 3e 0 29 meaning in javahow to use compareto in javajava compare sttringsto compare javahow to compare characters in a string in javahow to check equality of two strings in javacomparing strings java with 3estring comparisonhow to compare a string to a string in javajava if check stringstring compare to function javadifference in strings valuecompareto 28 29 string javacomparing strings in java not 3d 3d 3d between two stringshow to make a string equal another string javajava equal stringsstring equal comparison in javahow to compare strings in javshow to compare strings in java using if statementshow to compare the two strings in javawrite a program to compare two strings in javacomparing 2 string give falsecompareto in java strnigcheck to strings in javajava comparing two stringjava compare more than two stringshow to compare two strings in javatext comparison in java write a java program to compare two string java compare string contentcheck strings in javajava string comapreto compare string values in javajava comparing to strings 3d 3d between 2 strings in javahow to compare 2 binary strings in javacheck equality of two strings in javacheck if a string equals javacomapre strings in javajava string compare onlinejav chk stringcompare string equality javastring operators used to compare with stringcompare strings meaning javaif srting javacommpare two string in javastring comparecompare string java with with part of stringstrings compareto javajava how are strings comparedcan you compare strings with 3d 3d javajava two string 5b 5d comparsioncheck if 2 character strings are identical javahow java compare stringscomparison javahow ot compare string in javastring java comparecompare two strings in javacompareto 28 29 method in javajava comparer 2 stringjava compareto functionbefore and after comparison of string javahow to compare two string in javajava string comparison using 3d 3dstring comparison 3e in javacan we compare two strings using 3d 3d in javastring compare method in javajava how to compare two stringcompare two strings if they are equal javahow to comapre two strings in javacompareto javajava check for two equal stringscompare string with character javacompare strings ajvastring comparison with 3d 3d javacompare to strings javacompareto string method in javaif comparsion for strings javastr compare javacompare 28 29 javacompare value of teo strings in javastring equality in javacompareto method in strings in javajava if string equals stringjava compare two stringscompare length of two strings javacompare string value 3e in string comparison java 3d 3d operator java comparing stringsjava compareto two stringsstring comparing javastring comare in jacvacheck two strings for equality in java 21 3d string javacompares strings in javastrings string comparison in javamost accurate way to compare string in javaequality if string in java compare to javastring comparing functions javajava compare to methodjava string comparisionhow do you compare two strings in javajava compare strings by valuecompare string in jabahow to compare data of string in javahow to check whether two strings are same in javahow to compare string 5b 5d in javajava can i compare strings with 3d 3dcompare strings jaacompare string values in javacompareto method java stringcompare strinf javajava code for comparing string in datacompare if two strings are equal in javajava compare 26 how to check if a string is equal to something in javacompae stirng javato compare two strings in javahow compare two string in javacomparison between two stringsjava 8 compare stringsare this strings equaljava compare string equal tohow to compare two string objects in javastring compare java javacompare strings with 3d 3d javahow to compare string in java using ifjava strings compare equalstring equals javacompare two stringsin java one statementhow to check the equality of string data member to another data member in javahow do i compare a string name with four other string names in javastring compare to java 27compare strings javastring java comparetocheck if strings are different javaequality of strings in javatwo string are equal or not java methodcompare with javahow to compare strings javahow to check string equality in javacompare to stringin javahow to compare two stringscheck if 2 string are equal javacreate equal stringscompare method in javareliable way to compare strings javahow tocheck if both strings are equal in javawhy doesn 27t 3d 3d work to compare strings in javahow to compare string in if condition in javajava check stringtwo string equal javacompare method injavahow do you compare strings in javacompare strings differentjava compare tcompare a string variable with a string in javahow to compare two strings in java using comparatorchecking if strings are equal javacompareto in java stringcompare 2 string are same in javastring operations java comparing two stringshow to compair string in ifhow to check 2c stringcompare function javabuilstring compare string javacomapre two strings in java compareto in javacompare string java examplestring1 3d 3d string2 javacompare string javahow to use string compare in javacompareto in string javastring coparison jkavajava compare strinscompare string and string object in javacompare to use in javahow to compare styring in java 3d 3d string in javahow to compare class string to normal string in javastring compare javawrite a program to compare the strings given below 2c string 1 should be compared with all the other stringshow to compare string in java in if conditionjava compare tocheck if string equeals stringhow to compare string in java examplejava compare stringecompare fubction javacheck if 2 strings are equal javacomparing strings in java with 3d 3di need to use comparator to compare two string typeshow do strings compareif two strings are equal javahow does compare to work in javacompare two strings in java using inbuilt funjava language check if two strings are equalstring comparision javacompare different string javacheck string equal in javatest strings equal javacompare tp strings javastring class compare javastring equals new stringjava compare two strings similarityand string java ifcomparer 2 string javaequality string in javasee if two strings are equal javajava compare string that have umlathow compare two strings in javajava check equality of stringswhich method is used in string to compare string in javahow to compare string javawhich is the most reliable expression for testing where the value of two string variable are the same 3fcompare two stirngs javajava best string comparisoncompare three strings javacompare two string in jvacompare a string in javato check if two strings are equal in javacomparing two stringscomparing of two strings in javajava compare two string equaljava how does compareto workstring comparison in java using ifjava comparetohow are strings compared in java comapring string with the same lenght javahow to compare the strings in javawhen compare string javahow to compare a string in javachack string javacomparing strings if st javacheck if two stringsare equal javacomparing two strings javahow to compare values javastring values are compared using 27 3d 3d 27 not 27equals 28 29 27java how to compare strings with compare methodcompare to in java stringsequate strings javacompare 2 string javajava comparing two stringsjava compare valuejava string comparerjava method to equal two stringsif string javastring compre javahow to compare string in jvacompare 28 29 javacan i use 3d 3d to compare strings in javamatch string in javaor in java stringstring compered javado strings always need equals to compare in javacamparing two stringjava compareto with string java comparecomparing in javahow does string comparison work in javastring compare to method javacompare to on string prperty javahow to check if string equal in javacompare string in jvavbest way to compare two strings in javastring compare java deviateshwot to compare to strings javacompare content of two stringstring compare javahow to compare strings values in javahow to compare two strings in if condition in javahow to check if two strings are equal javasccompare string in java using 3c 3ecomparing two string values in java less or morecode to compare two strings in javacomparing values of strings javahow to check if two string aare the same in javajava string comparetohow can i compare string in java 3fstring compare 28 29 javajava use 21 3d compare stringjava comparing examplehow to use compareto method in javafastest way to compare strings javacompareto 28 29 string in javajava compare two strings examplehow strings are compare in javacompare strings in if statement javacompare to string javastring compare 28 29 javajava checking string equalitycomparing two strings in java 8can you compare three strings in javajava compare 2 stringcompare of two string in javastring compare in j vaacompare strings in javajava compare 2 stringscompare substring in javahow to compare string in javacoparing strings javacompare twostrings javacompare function for string in javatest whether strings match javajava string compare tojava compareto stringscompare strings in jjavacompage string javacan i compare two strings in javacomparing two strings in java with equals 2c compareto 2c 27 3d 3d 27java compare two sets of stringshow to compare string in if using javasting compare javaequals or 3d 3d string comparison javahow to check stringhow to compare string with number in if statement in javacheck equality of string javacompare two strings in 5cjavajava best way to compare stringsjava compre two stringswhere is compare method in javajava check if 2 strings are equalhow to compare two strings are equal in javahow to check if two strings are equaljava compareto stringstring comparison in javastring equality javajava compare 2 stirngshow to check if two strings are equal in javahow to compare 2 string 3d 3d in javacompare strring javastr compare in javacan 3d 3d be used to compare strings in javahow to check equality of string in javaif condition to compare two strings in javacompare to in javahow to check string is eqaul to another string using in java 3fcompare to in string in javacan you compare strings with 3d 3d in javacheck if string equals string 5b 5d java compareto java stringjava string compareto stringhow ot do string comparison in javajava string comparison operatorsto compare string in javathe to compare javajava string string comparehow to comapre two string in javacomparing strings with 3d 3d javahow to compare multiple strings in javacompare to method in javajava string compareto 28 29string compare function javastrings comapreto javacompare strings java equalscheck equal strings javaif else string comparison in javajava compare string equal or notcheck string equality javawhere to compare two stringsjava string in if comparejava compair string equalsjava string comparrisonstring equals 28new stringhow to compare to strings in javacheck if string equalsto compare two string objects 3astring equal checker in javahow to compare works in javacomparing the strings in javahow java compares strings by defaultcompare native string in javacompare string value in javacompare a part of string in javajava compare if two strings are equalhow toi compare strings in javahow to compare two strings in javasccopmaring string in javacomparing two string variables in javahow does compareto work in javajava comparing stringshow to compare to string in javachecking equality of 2 strings in javastring 3d 3d string java2 string not campare in javacompare string in java if statementjava string equal tocan we compare strings in javaequality string in if in java how to compare two string javahow to compare stirngs javahow to compare two strings in java in orderjava compare two stringstring comparison oin javajava comparing two words in a stringhow to compare a stringcompareto 28string cadena 29 javacompare equality of two strings in java java comparing 2 stringscompare string equal javacompare one string to anothercheck string value in javacheck if two strings are the same javastring comp javacomparing string with 3d 3d in javajava compare stringdcomparing to javahow to compare string values in javawhy can 27t we compare string in java using 3d 3dstring compareto method in javacompare three strings in javacompare two string in havawhat string not compare javastring compare injavacompareto method in javaverify string with 2 variables javacompareto 28 29 in javacompare string to string 5b 5dif string 3d 3d 22 22strings comparision in javajava string comparesjava compares stringcompare strings and or operator in javacompare string and string javajava most reliable way to compare two stringscompare operator string javacomparing to strings in javawhat happens if you compare strings in javacompareto method of string in javacomparing stringsin javahow to compare strings 7ecompare strings javacomparing two strigns in javacompare with string javajava check if strings are the samejhow to compare strings in javacompareto string function in javajava comapre two stringsmost reliable way to compare strings javajava how to compare multiple strings at onfcejava string compareto code2 strings compare javacan you compare strings in javastring compareto javahow compare a string in javacompare two strings with cosine similarity java compare string javacomparing string in javacompare stirng in javacompare to strings in javastring compare using 3d 3djava arrays comparematch two strings in javacompare strings 5b 5dhow to compare string if javacompare str javacompare function in javafunction to see if a strings content is equal to another strings contentcomparison of string in javajava if string equalscomparison betwwen strings javaif string 5b2 5d 3d 3d 22 22 compare to in javajava compare strings of different sizewhat is string comparison in javajava string comparecheck if string is equal javajava string equals 1 or 2compare strings in comparator javacompare to method javacompare string deviation in javajava comparingjavatuto compare string equality compareto java stringsjava compare functionstrings compare javahow to compare tring in javacompare two string in javacompare string using comstring meaning comparison javacompare string values javastring comparion in javacompareto java stringscompare teo string in javastring comparison using 3d 3d in javacompare char of string in javacan you compare strings using 3cevaluate 2 stringsstring compare to java documentationstring comapre in javajava check if two strings are equalcompare text jahow compare works in javacompareable string javahow to compare each string of two strings if they are equals in javahow to chcek string in javawrite an application that compares two strings that a user inputs from the command linehow to compare a variable to a string in javastring comparison methods in javajava how compare stringtext equals method java 285 29 write a program to compare the strings given below 2c string 1 should be compared with all the other stringshow to compare two string variables in javacompare two stringa in jvjava comparing strings codecompare in javamethod to compare two strings in javajava sting comparejava string comparison equalsto compare two stringsjava string compare methodcomparing the begining of string values javawhat does java string compareto dohow to compare values of string in javacompare method for string javastring compareto in javastring comparison in java using 3d 3dcompare stings in javahow will you compare string values in javaequal 2 strings javafunction compare between to string in javajava string equals another stringjava comparing string valueshow to compare stinrgs javacomparing string new stirng 28 29 javajava compare differeces between two stringscompareto on string javacan you compare two string in jhavastring java ifcompare chars in javahow to compare two strings in java using ifhow to compare two string if they are equal or not in javajava comparejava comare stringsif string equal to javacheck two strings are equalhow is strings compared in javausing string builder to compare 2 strings in javahow to compare string variables in javahow to compare java stringsset string compare javacheck value of 2 strings javahow to compare strings java 3fcomparestrings javacompare by 3d 3d in javacompare strings equal in javacompareto function in javacheck if two strings are equalhow to compare variable strings in javacompare string to string javahow to compare two string in javacompare strig in javajava string comparison 27java if compare stringshow to compare more than two string i javahow to compair string values in stringequating two strings in javawhat does compare do in javaque hace el metodo compare to javacompare in string javacan you compare 2 strings objects using 3ecompareto strings in javawhy w dont have string compare 28 29 javahow to compare if two strings are simularstring compare inm javastring compaare in javatest if two strings are equal javacorrect way to compare two strings in javahow to comparer srings in javato test two strings for equality you should use one of the two methods 2bcompare javajava string comparetohow to compare two string comparing to string in javastring 2 strings are equal or notstring compare in javajava compare stingcomparing 2 strings in javahow to compare content of string in javajava string comaretostring comparison greater than in javacompare string value java compare in javajava int comparetojava compare method for stringscompare to strings in javastringstring comparison javacompareto method javacan we use 3d 3d to compare strings in javacomparison in javacan you compare two strings with 3d 3d in javacomparing strings in javahow does java compares stringscompare values of two strings in javaverify 2 string are equal javahow to compare the two stringscompare string kavacomparing t javahow to compae two string in javacompare string in java if conditionstring compare in javaexample of compareto in javajava check values of two strings are the samejava method to compare two stringsjava compare to stringsjava to compare string equalityequality string javastring 3d 3d in javacomapre string javacompare string in javajava compare strings equalcomparing names in javahow to comapre strings 3e in javacomparing string javacompare method javajava string value comparisonstring compareto string javacompare two string according to compare 2 strings and print updated onestring equality check in javajava compare two strings