compare two strings java

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

showing results for - "compare two strings java"
Irene
25 Mar 2017
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
Jesús
24 Jan 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*/
Arianna
02 Oct 2016
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}
Lennard
27 Feb 2017
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  
Ethann
11 Oct 2016
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            }
Swan
20 Aug 2018
1// These two have the same value
2new String("test").equals("test") // --> true 
3
4// ... but they are not the same object
5new String("test") == "test" // --> false 
6
7// ... neither are these
8new String("test") == new String("test") // --> false 
9
queries leading to this page
compare two strings in java ifcompare string equal javacomparestrings javaif string 5b2 5d 3d 3d 22 22what operator to use when compare two strings in javacomparing two strings javamatching two strings codecomparer 2 string javacoparing strings javacompare two strings ljavajava two string equlaitystring compare java javahow to comapre strings 3e in javastrings compare javacompare string in jvavcompare of two string in javacompare to a javacompareto strings in javajava strings compare equalcan you compare three strings in javaproblem in comparing 2 strings javacomapre two strings javastring comp javahow to check string is eqaul to another string using in java 3fmost accurate way to compare string in javastrings comapreto javacompare text jajava string comaprecan we compare two strings using 3d 3d in javajava how to compare 2 strignsif condition to compare two strings in javahow to check whether two strings are same in javastring compare to function javawhat happens if you compare strings in javahow to compare strings in javscompare to stringin javajava comparing strings with 3d 3dstring 2 strings are equal or notwhat does compare do in javathe to compare method java 2bcompare javacomparing 2 string give falsecompare to in string in javajava compate stringsstring compare in java with equalshow to compare strings javacompare to strings javay should nt we compare number in string javabest way to compare two strings in javajava string equal tocomparing 2 stringcomparing strings javaequality if string in javajava compare stirngsstring compare in java compareto java stringscompare two strings with cosine similarity javacompareto in java examplejava method to compare two stringscomparing 2 string in javaare this strings equaljava comare stringscompare two stringsin java one statementcomparing two string in javahow to compare string in java eewhich method is used in string to compare string in javacompare method for string javahow tocheck if both strings are equal in javacompareto 28string cadena 29 javacomparision of string in javacompare two strings in if statement javaequals or 3d 3d string comparison javacompare two strings jacastring values are compared using 27 3d 3d 27 2c not 27equals 28 29 27how to comparte two tring in javahow to compare two strings in java using ifcompare string in java if statementif with string javacomparing two string 3d 3d javahow do you compare strings in javacomparing to javastring compare function in javajava compare textjava string comparecheck if string is equal javawhat does compare method do in javabefore and after comparison of string javaif string 3d 3dcompare two stirngs javaif 28str 5bi 5d compareto 28str 5bj 5d 29 3e 0 29 meaning in javacompare tow string in javajava compare to stringjava compare two sets of stringscompares strings in javacheck if two stringsare equal javacomapre two strings in javabuilstring compare string javamatch two strings in javahow to compare 2 stringshow to compare values of string in javacompare values in strings javacheck strings in javahow to compare the two stringsjava two string 5b 5d comparsionto compare java compareto java stringstring equal checker in javajava check strings for equalityjava compares string 3d 3d between 2 strings in javastring1 3d 3d string2 javamatch two stringcompare strings ajvastring compareto string javacompare two string in havahow to compae two string in javacompare to method in javacheck value of 2 strings javastring comparison in java with referencestring compare java deviatesstring comaparitioni javain java 2c how should i compare two strings to see if they are equivalent 3fstring comparison greater than in javacompare to on string prperty javajava 2 streing ewqualcompare strings 5b 5dcompare string in ajvajava string comparisoncompare tp strings javacomparing string new stirng 28 29 javacomparing strings in javajava string equals another stringcompare string in javaequality string in javajavatuto compare string equalityjava compare if two strings are equalfastest way to compare strings javareliable way to compare strings javajava compare differeces between two stringsjava string 21 3dcompare strig in javacompare three strings javajava best way to compare stringsjava compare 2 strings for equalityhow to string compare in javastring compare function javacheck if 2 strings matches javajava string equal to stringhow to compare if two strings are equal in javahow string comparison works in javastring comparejava string equalityhow to compare stirngs javacompareto in string javahow are strings compared in java compare by 3d 3d in javastring comparisoncompare strings in if statement javaque hace el metodo compare to javaif string and string are differentjava check values of two strings are equalhow to use compareto in javajava compare method for stringscheck string equality in javahow does compareto work for strings in javahow to compare two strings in java in ordercheck two strings for equality in javacompare strings javahow to compare string in if using javastring comparison oin javacompare strings java equals 3d 3d in string comparison javacheck equality of string javastring equals 28new stringcompare stings in javajava compare stringjava string comaretocompare string using 3d 3dcompare strings jaavmatch string in javacheck if string equeals stringhow to check and compare in javajava checking string equalitytwo string compare in javajava string comparasonjava how to compare stringshow to equal two strings in javahow to compare content of string in javacompareto 28 29 string in javahow to check the equality of string data member to another data member in javastring compered javajava compare two stringscompae stirng javajava comparehow to compare two strings in java which is greaterjava same string valuestring compare method in javacompare strings bigger than javahow to compare two string objects in javajava comparecompareto method javahow to compare to string in javacompare twostrings javacomparing stringsin javacheck equality of string in javadifference in strings valuecan you compare two strings with 3d 3d in javajava int comparetocompare string valuecompare two strings are equal in javajavatuto to compare string equalityhow to compare 2 strings in java for smallerhow to compare multiple strings in javastring compare in j vaaequality in strings with javacompare method javacheck if two strings are same in javacompare string to string javatwo string are equal or not java methodequating two strings in javahow to comparison of java stringsjava comparinghow to check equality of two strings in javato compare in javacomparison of string in javahow ot compare strinfs in javajava how are strings comparedcheck if string equal java2 strings compare javahow can i compare 2 strings in javastring comparion in javafunction to see if a strings content is equal to another strings contentstring compareto javacompareto 28 29 java stringsset string compare javacompare strings in comparator javajava string value comparisonhow to compare 2 string 3d 3d in javacomparing t javacompare content of two stringwhere to compare two stringsjava check for two equal stringsjava string compare onlinecan you compare 2 strings objects using 3ejava if string is a stringcompare strings in jjavahow to compare each string of two strings if they are equals in javajava string comparetoif 2 string matchstring compareto method javacompare multiple strings in javacomparae string in java comparing string objects in javacompareto method in strings in javahow to check if two strings are equal in javacomparison of strings in javahow to compare stinrgs javacompareto javajava string 3d 3d stringwhat does compareto do in javacompareto 28 29 string javastring comare javato check if two strings are equal in javajava compare 26 compare 2 strings in jjavachecking equality of 2 strings in javacompare string in java comaprtorhow to campare to string in javahow to use compare to in javawhy we dont have string compare 28 29 javahow to do string comparison in javacomparing strings with 3d 3d javastring compare injavajava comapre two stringscompare 2 stringshow to compare string in if condition in javajava how compare workscompare 2 strings in javastring comparison 3e in javacompare two strings javastring comare in jacvajava check if two strings are equalcompare function javajava string comparetohow to compare the value of two strings in javacompareto string method in java 3d 3d checks for java stringshow to check string equality in javacompare string valuescompare with string javajava string compareto methodhow compare works in java 285 29 write a program to compare the strings given below 2c string 1 should be compared with all the other stringscheck if two strings are equaljava comparing stringjava comparte 2 stringscomapre two string javahow to compare 2 strings javacan i compare two strings in javastring comparing javahow to compare stringshow to write a compare method in javacompareto java stringhow to check if two strings are not the same in javacompare between two strings in javajava compareto functionif srting javafinal compare strings in javajava compareto stringscompare teo string in javahow to compare a string in javacompare fubction javahow to write a compareto 28 29 method in javacompare to strings in javastringjava string comparesstring equals new stringcompare function strings javacomparing to string in javacomparing names in javaequality string javastrcmp in javajava method to equal two stringsequality string in if in java compare a part of string in java compare to javawrite a java program to read two strings from command line argument and check the equality of two string using string function compare two strings in java without case sensitivecompare two strings using boolean function in javamost reliable way to compare strings javastring class compare javahow to comapre string in javastr compare javahow to compare a variable to a string in javajava compare two string equalstring java comparetocompare strings meaning javahow to compare two srings javatwo strings equal javacomparing javacan we use 3d 3d to compare strings in javaequality of stringsstring comparision in javaequals compare stringstring comparison method javacompare two string in javajava compareto with string java if statement compare stringscompare 1 value of a string to each other value in the string javacheck string equality javacompare value of teo strings in javacompare string content javastring comapre in javajava how to compare string valuescomparing string javastrings string comparison 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 javahow to compare string variables in javacompare two string according to compare string values javahow to check if string equal in javacompareto between strings javajava check if strings are equaljava string comparrisonjava compare string valuescheck if a string equals javajava compare two strings similarityhow to compare two string compare with javahow to commpare two strings in javastring 1 3d 3d string 2how to compare one string to another in javastring operations java comparing two stringsjava string comparison 27how does java compares stringscompare substring in javacompare the two strings in java 2c compareto 28 29 2c in java stringhow does string comparison work in javacompare strings equal in javacompare in string javacomparing strings content javajava compare 2 stringsto compare string in java 3d 3d 3d between two stringscompare string deviation in javacompare stringjava compareto method stringshow to compare works in javato test two strings for equality you should use one of the two methodstest if two strings are the same javahow to compare 2 binary strings in javacan you compare strings with 3d 3d in javajava 3d 3d for string comparisoncomparison in javacompare to in java stringscompare string values in javahow to compare strings java 3fjava string comparison using 3d 3dsame string equality of two strings in jstring compare javacompare string in java using 3c 3ehow to chcek string in javacheck if strings arent ewual javaare strings comparable in javacompare two strings if they are equal javastring 3d 3d string javacompare equality of two strings in java how to compare 2 string in javastring compare 28 29 javajava string comparetocompare one string to anotherhwo to compare two strings in javawhen comparing strings in javajava compare show to compare strings in ajvacompare 2 string in javacomparing two string javawhen compare string javahow to compare the strings in javacompare a string variable with a string in javajava compareto methodcompare strring javacheck whether two strings are equal or not in javacompare two lists javacompare string and string object in javajava comparing two words in a stringcorrect way to compare two strings in javahow to compare a stringhow to compare two strings in javahow to compare a variable with a string in javajava check equality of stringsjava compare string ifhow to compare strings in jaajava compareto two stringshow to compare more than two string i javasting comparison in javacan we compare strings in javajava comparing two stringsstring compare 28 29 javacompare two stirng in javajava string in if comparehow will you compare string values in javaexample of compareto in javahow to use string compare in javajava if check stringhow to test string in javastring operators used to compare with stringcompareto 28 29 method in javacheck to strings in javajava compare string contentif string equal to javacompare stirng in javawhat is string comparison in javacompare two string javacomparing strings using the methods equals 28 29 in javawhy can 27t we compare string in java using 3d 3dcompareable string javahow to check 2 strings are equal in javahow to compare string in java using ifjava compare strinscheck for string equality javahow do strings comparehow to compare the string in javawrite an application that compares two strings that a user inputs from the command linejhow to compare strings in javajava if compare stringsjava compareable stringcompare string equality javacan i use 3d 3d to compare strings in javajava compare strinfchecking string equality in javacompareto in javacomaprinf two strings using boole an javahow can i compare string in java 3fcomparing of two strings in javacompare 28 29 javajava comparing examplecomparing to strings in javastring equality check in javacheck if 2 character strings are identical javacompare string javastring compareto javajava compareto in javacheck if string equals string 5b 5d javastring comparison in java using ifhow to check if string equals in javacomparing strings with string in javato compare string values in javacomapre strings in javahow to compare if two strings are simularwhy doesn 27t 3d 3d work to compare strings in javacan you compare strings with 3d 3d javahow oot compare string in javahow to compare data of string in javahow to compare two string in java compare in java compare to in javaverify string with 2 variables javahow to check if a string is 3d 3d to a different stirng javahow to compare two strings javawrite a program to compare two string in javaexplain the compare function in java 27prelims 27 or 27both 27 how to compare two string with one string using orfastest way of compare strings javahow to compare string in java in if conditioncomparing string equality javahow to compare string with stringstring compare in java 3d 3d string in javajava comparing 2 stringscompare strings in javacompareto method java stringcompare is a string is the same as an other string javahow to check equality of string in javahow to compare variable strings in javajava compare stringehow ot compare strings javajava compare functionjava comparing strings using 3d 3dcomapre string javajava compareto stringhow to check if a string is equal to something in javajava compare stingstring compare using 3d 3dstring values are compared using 27 3d 3d 27 not 27equals 28 29 27how to compare strings values in javastring java ifhow to compare data in strings javacompare strings with 3d 3d javacompare in javacheck string equal in javawhat can you compare with compare to in javainbuilt function to compare two strings in javastring compare to java 27using if to compare strings javacompare function for string in java 3d 3d com 2 stringsjava if comparing stringshow to compare string literal in javacheck string value in javahow to check string in javajava comparing strngstring compare javac 2b 2bjava how compare stringwhy we cannot compare strings in java2 string not campare in javajava how does compareto workcheck equality of two strings in javacompare str javacompare two strings with one different character in javacomparing string in jvacomparing strings java with 3eode to compare strings in javatest whether strings match javacompare three strings in javahow to check if two strings are equal javascjava compare a stringjava string compare functioncompare string 5b 5d javacompare javahow to compare the two strings in javacode to compare two strings in javastring method for comparing javahow to compare 2 strings 3fmethod to compare two strings in javastring 3d 3d in javatwo string equal javacompareto java stringscompare to function java stringjava compare sttringscompareto of string in javahow does compareto work in javacompare string with equals javahow to check string value in java 3fcompareto method of string in javahow to compare string values in javajava string compare valuejava compare two strings examplestring comparison in java using 3d 3dtext equals method javastring conparision in javahow to compare java stringscompare in java stringcompare if two strings are equal in javajava comparetostring comparing functions javajava to compare string equalityjava string compareto codecomparing string in javajava how to compare strings with compare methodcompareto string function in javajava if string equals stringhow do i compare strings in javacompaer strings in javafunction compare between to string in javacompare different string javacompare string value javahow to compare a string to a string in javajava how to check if strings are the same valuechack string javaverify 2 string are equal javahow to check if a string is equal to another string in javacompare string java 3d 3dstring comparison using 3d 3d in javahow to compare two string javajava check values of two strings are the samecompare two stringsjava comparingwithjava compare strings with errorshow to comapre two strings in javajava string equals 1 or 2java compare methodcomparing values of strings javacompareig 2 string javaequality of strings in javajava comparatorhow to compare two string in javacomparing 2 strings in javacompare string function javastring compare methid javahow compare two string in javahow to compare two strings are equal in javajavav compare stringcheck if 2 string are eaquljava how to compare multiple strings at onfcehow do i compare a string name with four other string names in javacompare two strings which have one different character in javahow to compare strings in jqjava string compare methodhow is strings compared in javacompare 28 29 strings javacompare string with character javacompare strings jaajava 2 string comparea compareto 28b 29 in javahow to compare to strings in javacompareto 28 29 javastring compare to javajava string comparison methodsjava string compare tojava string compare to how it workscompare to in javahow to compare with a 22 in javastring equal comparison in javajava compare valuecompare 28 29 method in javahow to compare strings in sjava compareto on string javawhat does java string compareto docan you compare two string in jhavacompareto string in javacompares two strings javacompare values of two strings in javatext comparison in javastring method to compare two stringscheck if strings are different javahow to check 2c stringcomparing two string variables in javacomparing the strings in javahow to compare styring in javacompare to string in javacopmare strings javacheck if string equal to string javacheck two strings are equalcomparing strings in java if statementtest if two strings are equal javahow to check if string equals in java in if statementcompare a string with another string in javacompare to string javacompare two strings in javajava string compareif string 3d string javajava compare 2 stirngscompare sring values javajava equal stringscompare string to string 5b 5dhow to compare strings and variables javahow java compare stringsccopmaring string in javacompare 28 29 in javahwot to compare to strings javastring compre javajava compare strings equaljava compre two stringscompare stringsstr compare in javacompareto string method javacompare 2 strings javachecking if strings are equal javahow to compare two stringsjava how to compare two stringwhere is compare method in javacomapre string in javacompare native string in javacompareto in java strnighow to compare string javastring equality in javahow to compare string with number in if statement in javaand string java ifcamparing two stringequal 2 strings javacomparing to strings to each other javahow to compare string 5b 5d in javajava comparing stringsbest way to compare strings in javacompareto java iof both string equalhow to match string in javacompare betweeen strings javastring comparison in java using equalsjava compare two stringcompare two strings in 5cjavastring compare to java documentationcompareto string javacomparing strings in java with 3d 3dcheck 2 strings are equal in javacheck two strings are equal in javacomparing in java compare string javahow to compare two string if they are equal or not in javahow to comparer srings in javastrings compareto javahow to compare string in javahow compare two strings in javajava compare to strings compareto in javahow to compare string in java examplestring compareto method in javacompare string java with with part of stringequate strings javacompare string in jvastring compareto in javaif string 3d 3d string javajava most reliable way to compare two stringsjavatuto compare two stringcomparing two strigns in java 7ecompare strings javahow to make a string equal another string javamethod to check string equalitycompare method in java for two stringshow to compare tow strings in javacompare if two strings are equal javacomparison two stringshow to compare two string variables in javacompare string value in javatest if strings are equal javacompare twostring in javahow to compare stringjava comparer 2 stringjava string string comparecompare strinf javacompareto method in javacomparing two strings in java with equals 2c compareto 2c 27 3d 3d 27compare 2 string are same in javahwo to comate strings in javacomparison javawhat string not compare javawrite a program to compare the strings given below 2c string 1 should be compared with all the other stringsusing string builder to compare 2 strings in javajava compare tjava compare string equalcan you compare strings using 3cif two strings are equal javastring coparison jkavacompare length of two string in javacompare char of string in java write a java program to compare two string can you compare strings in javajava comparetojava string compareto 28 29java compare toto compare java 3d 3d operator java comparing stringsstring compaare in javacomparison betwwen strings javastring compare java 3d 3dhow to compare values javacomparing two strings in java 8sting compare javaif string javahow to check if two strings are equalthe string method compareto 28 29 returnshow does compare to work in javajava compare string equal tostring and new string compare javajava code for comparing string in datajava how to compare to stringscomparison between two stringsstring comparison with 3d 3d javahow to compare the string value whether they are same or not in java java compare stringscompare two strings in java using inbuilt funhow do you compare two strings in javacompare strings in java not equalcompare to use in javahow java compares strings by defaultcheck equal strings javacompare a string in javajava test string equalsjava string comparisionjava string comparison equalsusing string with compare in javastring comparison in javastring comparison javajava compare strings of different sizejava check if string is equal to another stringhow to compair string in ifhow to compare string if javacheck if 2 strings are equal javajava sting comparejava 3d 3d string comparisonjava best string comparisoncompareto strings javacompare 2 strings and print updated onecommpare two string in javacomparing two stringscompare string in jabacompare string kavacompare 28 29 java 3e in string comparison javacompare string in java if conditioncomapre strings javacompare 2 string javahow to comapre two string in javajava can i compare strings with 3d 3dhow to use compareto method in javahow you compare two strings in javacompare to method javacompare string java examplehow to compare 2 strings in java for smalli need to use comparator to compare two string typesjava comparing string valuesjava sring comparehow to check equel between stringcompare two stringa in jvcompare two strings in java using 3d 3dcompareto by string javastring compare to method javajhow to compare 2 string in javastrings comparision in javahow to compare substring in javahow to check stringhow do you compare strings in java 3fhow to compare strings in java using if statementshow to compare two strings in if condition in javacomparing two string values in java less or morestring compareto in javastring equals javastring java comparecan you use 3d 3d to compare strings in javacomparing 2 strings javacompare 2 strings java comparatorcomparator java how to compare stringdo strings always need equals to compare in javastring equate javacompare string is javacompare 2 strings java if statementstring compareto java examplecheck if string equal in javahow to compair string values in stringjava check if strings are the samecompareto function in javahow to compare two strings 3fstring equality javahow to check if strings are equal in javause compareto method for comparing two strings in java 5cjava if string equalsjava arrays comparecomparing strings in java notjava 8 compare stringscompare strings javqstring comparison methods in javahow to compare strings in javacompare method in javacomparison operator for string in javastring meaning comparison javacompare operator string javajava comparing two stringjava compare string that have umlatjava check if sting is samehow strings are compare in javahow ot do string comparison in javajava comparisoncreate equal stringsto compare two strings in javajava string comparison operatorsjava compare stringdthe to compare javastring compare javajava language check if two strings are equalcomparing two strings in javawhich is the most reliable expression for testing where the value of two string variable are the same 3fwrite a program to compare two strings in javastring1 equals 28string2 29 javahow to compare two strings in java using comparatoror in java stringcompare method injavahow to check two strings are equal in javacompare twoo strings in javajava compare more than two stringscompare javajava comparing to stringscompareto in java stringhow to compare 2 strings javastringcompare to javahow toi compare strings in javacompare java stringcomparing strings if st javacompage string javacomare two string in javacompareto 28 29 in javahow to compare class string to normal string in javacompare function in javahow to compare tring in javacomparing string object in javahow ot compare string in javastring value comparison in javastring value compare in javacompare value javacheck if 2 string are equal javahow to compare two elements of a string iin javajava checking stingcompare string and string javahow to compare 2 strings in javaif comparsion for strings javacomparing string with 3d 3d in javahow to compare to stringscomapring string with the same lenght javacompare two stringtest strings equal javacheck if two strings are the same javajav chk stringsee if two strings are equal javacompare two string in jvajava check stringstring comparisonsif string 3d 3d 22 22java compare string equal or notcompare differences between two strings javacomparing the begining of string values javajava string compareto stringjava comparator comparing stringjava comparing strings codehow to equal to stringevaluate 2 stringscan you cmopare strings with 3e 21 3d string javajava use 21 3d compare stringjava compare strings by valuehow to use to compare method n javajava compare to methodhow to compare two strings in ajvahow to compare two strings in java 3fjava compare 2 stringjava can you check if a string 27s address is equalstring comparision javajava check if 2 strings are equal to other 2 stringsif else string comparison in javacheck if two strings are equal in javacompare to strings in javacompare string using comcheck if string equalshow to compare two given strings in javacompare length of two strings javajava string comparerhow to compare characters in a string in javahow to compare string in jvacompare strings and or operator in javacompare two string equality in javacompare strings differentwhy w dont have string compare 28 29 javato compare two string objects 3acompare chars in javawhich of the following are use to compare a string value 3fhow to check if two string aare the same in javastring comapre javato compare two stringshow compare a string in javacan 3d 3d be used to compare strings in javahow string compareto works in javajava check if 2 strings are equalhow to compare two strings in javasequals string comparison javacompare two strings java