java how to compare strings

System.out.println("hey".equals("hey")); //prints true

/*
	always use .equals() instead of ==,
    because == does the compare the string content but
    loosely where the string is stored in.
*/

4.5
2
Lionel Aguero 33605 points

                                    String1.equals(String2)

4.5 (2 Votes)
0
4.2
5
Awgiedawgie 440215 points

                                    // These two have the same value
new String("test").equals("test") // --> true 

// ... but they are not the same object
new String("test") == "test" // --> false 

// ... neither are these
new String("test") == new String("test") // --> false 

4.2 (5 Votes)
0
5
1
Phoenix Logan 186120 points

                                    // compare two strings in java using String.equals() method in java
public class EqualsMethodDemo
{
   public static void main(String[] args)
   {
      String str1 = new String("HelloWorld");
      String str2 = new String("Flower");
      String str3 = new String("Hello");
      String str4 = new String("Hello");
      String str5 = new String("hello");
      // compare str1 != str2
      System.out.println("Compare " + str1 + " and " + str2 + ": " + str1.equals(str2));
      // compare str3 = str4
      System.out.println("Compare " + str3 + " and " + str4 + ": " + str3.equals(str4));
      // compare str4 != str5
      System.out.println("Compare " + str4 + " and " + str5 + ": " + str4.equals(str5));
      // compare str1 != str4
      System.out.println("Compare " + str1 + " and " + str4 + ": " + str1.equals(str4));
   }
}

5 (1 Votes)
0
4.38
8
Phoenix Logan 186120 points

                                    if (aName.equals(anotherName))
        { 
            System.out.println(aName + " equals " + anotherName);
        }
        else 
            { 
                System.out.println(aName + " does not equal " +anotherName );
                           
            }

4.38 (8 Votes)
0
4.13
7
Awgiedawgie 440215 points

                                    // These two have the same value
new String("test").equals("test") // --> true 

// ... but they are not the same object
new String("test") == "test" // --> false 

// ... neither are these
new String("test") == new String("test") // --> false 

4.13 (8 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
string compare function java how ot do string comparison in java check if same string in java compare 2 string are same in java how to compare strings values in java java String.compare How do you compare strings in Java? to compare string values in java string comparion java how can I compare string in java? java compare with ? why we dont have String.compare() java why w dont have String.compare() java compare string in java using < > how to compare two strings in if condition in java comparing string with == in java string compare java java compare by == in java comparing strings in java if statement check if 2 strings are identical java string comparison in java with reference reliable way to compare strings java string comapre in java compare teo string in java string.compare in java java string .compareto how compare two string in java strings comparision in java set string compare java compare String and String object in java > in string comparison java java string comparison equals java check if two strings are the same how to compare two strings are equal in java compare twoo strings in java to compare method in java how to compare values of string in java java compareTo with string why doesn't == work to compare strings in java how to compare two string objects in java check if two string is equal in java can i compare two strings in java best way to compare strings in java explain the compare function in java compare string with equals java java compare value string comparison using == in java java string compare value compare string in jaba string comaparitioni java java compare more than two strings java check if string equals another string or or compare to function java string compare two strings in if statement java how oot compare string in java java how compare works javav compare string compare string in ajva string.compareto in java how to compare the string in java comapre two strings in java how to compare class string to normal string in java string compare to java compareto of string in java string compare to method java how to compare strings in java using if statements java compare two strings similarity java compare() compare the two strings in java java how to compare to Strings how to compare 2 strings in java for smaller how to compare 2 strings in java for small str.compare in java compare to strings java comparing two strings java java compare sting string character comparison in java how compare two strings in java compare string java == string comparison methods in java can == be used to compare strings in java how to check two strings are equal or not in java java comparing string values java string comareTo if condition to compare two strings in java java string comparision how to check if two string are equals in java hoe to check if strings are same in java compare string value in java java compare if two strings are equal java string compareto string compare different string java java how to compare 2 strigns string compater in java how to use to compare method n java the to compare method java the to compare java how to check string is same or not in java compare java how to compare multiple strings in java compareto by string java string compareto method in java how to compare string values in java how to comapre two string in java 2 strings compare java compareto implementation java string how to check two string equal in java comparing of two strings in java compare method injava java compare stringe java compareto method strings string compares in java compare if two strings have same value java how to compare string in if condition in java How strings are compare in java java compre two strings what does compareto return in java with string how to compare two strings in java using comparator function to check two string are same in java string compare java deviates compare string deviation in java java string comparison methods How do I compare strings in Java how to check string value is equal to another value in java comapre string in java commpare two string in java how to check if string are equal in java compare of two string in java why can't we compare string in java using == how to compare strings in sjava how you compare two strings in java java string compare to can we compare two strings using == in java how to write a compare method in java how to compare variable strings in java compare strig in java most accurate way to compare string in java checking equality of 2 strings in java comparison java compare string in jva java string compa how to check if twir string is samen in java comparing 2 strings java java check if string is equal string comparision in java compare string with character java coparing strings java how to compare two strings in javas what does compare method do in java java string in if compare compareto in java strnig java check if string are not the same hwo to comate strings in java string compares too in java java comparing example +compare java code to compare two strings in java how to compare two string java java compare function compare to in java strings check if string is same java how to string compare in java compareTo method java string compare two strings if they are equal java why we cannot compare strings in java java check if two string are equal compare strings and or operator in java compare strings equal in java builstring compare string java compare() java how to compare works in java how to compare two string in java java check equality of strings how to compare a string in java compare to method in java compareto string function in java java best string comparison compare str java compareTo on string java compareto strings in java where is compare method in java how does compare to work in java java if two string are equals length compare twoStrings java to compare in java .compareto java string how to comapre strings > in java java how to compare multiple strings at onfce how to compare to strings in java how to check both the string or equal or not in string in java how to compare data of string in java program to check if two strings are equal in java java compare differeces between two strings how to compare two strings in java in order method to compare two strings in java comparing java what string not compare java string compareto method java compare to a java compareto java string comparison of string in java compare native string in java how to check if the value in a string variable and the string is same in java check if strings are identical java java compare stirngs how to compare strings in javs compare value java java compate strings compare function strings java comparing in java can you compare strings with == java how to compare styring in java compare() java string compare() java check 2 strings are equal in java compare function java compare method for string java comparing strings content java write a program to compare two strings in java java string comparison using == compare two stringsin java one statement compare multiple strings in java compare three strings in java str compare java how to check string equality in java java check two strings are equal java compare strinf check two strings for equality in java Compare to use in java using string builder to compare 2 strings in java java comparingwith compareto() string java equality string java Write a program to compare two string in java compare strings in comparator java compare in java string compareto method of string in java function compare between to string in java java check if string is same how compare works in java strings compareto java compare two strings are equal in java how to compare two elements of a string iin java compare in string java comparer 2 string java can we use == to compare strings in java java string compareto method JAVA find if two strings are not equal compare value of teo strings in java how compare a string in java fastest way of compare strings java compare string java with with part of string string comparison in java using == string comparison in java using if compare stings in java java compareto string java compare strings of different size compare string java 8 How to compare string if java compare function in java check if two string are equal in java how does compareto work for strings in java string equality java java compare to string In Java, how should I compare two Strings to see if they are equivalent? how to check if both strings have same letter in java how to check if the string is of same letters in java how to compare if two strings are equal in java java comparing how do you compare strings in java compare a string with another string in java comapre strings in java compare is a string is the same as an other string java strings comapreto java java 8 compare strings string equality check in java compare to string in java check if two string are equal java how to compare 2 strings javastring String Comapre java java .compare how to check and compare in java to compare java == in string comparison java how to compare the string value whether they are same or not in java comapre string java compare() in java check if two strings have same in java comparing strings in java not how to compare string in java in if condition how can i compare 2 strings in java compare strring java how to check if two strings are equal java string.compareto java java check if two strings are different two string compare in java how to compare data in strings java how to tell if two strings are equal java check whether two string are equal java == operator java comparing strings check if 2 strings are equal in java if (str[i].compareTo(str[j]) > 0) meaning in java what is string comparison in java java compare method fastest way to compare strings java java comparator.comparing string compare java strin lexi string compareto in java compare strings in java not equal string value comparison in java .compare to in java java if a string is equal do something .compare in java compare strings in java compare strings in if statement java compareto in java string string comparison greater than in java string comparison > in java sting comparison in java string comparison with == java .compare string java compare string[] java java string equality string compareto java how to check whether 2 strings are equal in java how to compare two strings in java using if comparing two string variables in java how to compare string java string java compareTo java string compareto java string compares java string compare online comparing strings with string in java comparing two strigns in java java compare T how to compare two string if they are equal or not in java java sting compare compare to Java java compareto strings STRING COMPARING JAVA java comparing Strings code how ot compare strings java compareto() string in java what happens if you compare strings in java how to check strings are equal in java compare in java check if strings are equal java java string compareto when comparing strings in java compareTo Strings java java string comparisons java string string compare java arrays.compare java int.compareto The String method compareTo() returns java .compareto java comparator what can you compare with compare to in java compare two string in jva compare string values in java java compare sttrings how to compare string variables in java how to check equality of two strings in java compare java string comparing string in jva what does compare do in java java string comparer check same string java how ot compare strinfs in java string equal comparison in java comparing values of strings java how to check two strings are not same in java java 2 string compare how to compare two given strings in java java compare to method java string compare operator java compare string that have umlat how string comparison works in java java compare s how to check if strings are the same java string value compare in java Java compare strings with errors can you compare two strings with == in java java compare string content equals or == string comparison java compare strinf java java comparing strings with == compare to string java compare to on String prperty java string equality in java java comparer 2 string compare a string in java java check if 2 string are equal compare string equality java Java String compareTo() string character compare java java how to check if two strings are equal what does java string compareto do string compare in java with equals string compare function in java java string compare method can you compare two string in jhava how to check if one string has the same values of another string java string compare method in jaVA string compareto string java java compare string lexi compare with java can we compare strings in java most reliable way to compare strings java compare method java check if 2 strings are the same java javatuto to compare string equality java to compare string equality javatuto compare string equality java string compare to how it works compare strings java .equals javatuto compare two string compareable string java correct way to compare two strings in java string compare to java' java string compareto code compare string and string java compare string content java string operations java comparing two strings comparing string equality java java compare string equal to compares strings in java java if statement compare strings string compare injava how to check 2 strings are equal in java check equality of two strings in java java two string[] comparsion ..compareTO java strings how to compare 2 strings java java string comapre Write a Java program to compare two String. string compare java how to check if two strings are the same java compareto string in java check two string equal in java how to check if 2 Strings are equal in java compare to in java how to test if two strings are equal java java comparison .compareto string java check if string same java java compare to comparing strings java with > java how compare string compare with string java java string value comparison java compares string compare method in java to compare java how we check two string are same or not in java `java compare string in contains compare to method java java find out if a string is equal to another java compare how to check if two string are equal in java compareTo string method java how to compare two strings in ajva comare two string in java java check if two strings are equal string class compare java string == string in java comparison two strings java check if equal compare two string equality in java text equals method java match two strings in java == com 2 strings check for string equaity java compare two stirngs java compare values in strings java compare if two strings are equal java string java if how to check String value in Java ? string comparion in java chack string java check if 2 strings matches java how to compare string in jva compare string using == java check if 2 strings are equal to other 2 strings how to compare substring in java how to compare characters in a string in java string and new string compare java java compare String if compareto() java if string == java check if string is the same java how to compare two string variables in java java compareTo in java compares two strings java how to compare two strings in java which is greater how to compare two Strings java check if two strings are equal java string compareto java example java string equalsTo how do you compare two strings in java if srting java equals to compare strings java checking if two strings are equal compare two stirng in java how to check equality of string in java java comparing two strings check two strings are equal in java java if string is a string how to check string is eqaul to another string using in java? To test two strings for equality you should use one of the two methods strings compare java how to check if a string is equal to something in java how to match string in java compare two strings jaca comparing two string in java check if string is equal java i need to use comparator to compare two string types compare substring in java how to use compare to in java copmare strings java java how does compareto work how does compareto work in java how to check compare strings in java compare two string in hava string comparision java string comparison in java using equals compare string equal java java 2 streing ewqual if string = string java compare content of two string compare strings jaa can you compare strings with == in java comapre strings java string meaning comparison java if string is java string equals new string compare two string according to jhow to compare 2 string in java do strings always need .equals to compare in java java checking string equality test if two strings are equal java compare java java check string equals check if string is one of java compare strings javq compareto java equality of strings in java check to strings in java java compare two string java method to compare two strings compare values of two strings in java string compare to compare two string java if equal compare fubction java compare char of string in java java test string equals string compare to java documentation or in java string comparing string java how to test string in java que hace el metodo compare to java == string in java string compare string compare online compare chars in java how to check two strings are equal in java comparator java how to compare string how to comparte two tring in java how to compare two strings in java ? compare two strings with cosine similarity java compareto java iof both string equal online string compare to compare two strings compare two strings in java without case sensitive check equal strings java java compare 2 stirngs string java compare string == in java compage string java string equal checker in java compare 2 strings in jjava how to compare string in java ee how to equal two strings in java java can you check if a string's address is equal how to check if string is in other java compare string values how to check if two strings are not the same in java camparing two string how to check equel between string two string equal java java compare 2 strings how to compare strings java? compareto string method in java java string.compareto compare two strings in java if comparing to strings in java how to comparison of java strings String is same java before and after comparison of string java java compare string values how to use compareto in java string comparison oin java ~compare strings java compareTo method in strings in java how to write a compareto() method in java How to compare strings in jq compare string in java if statement can you compare strings in java best way to compare two strings in java which is best for string comparison equals or == in java how to check if string equal in java java compare text jav chk string STring compare in j vaa string == string java can you compare strings using < compareto string java how to check , string how to compare two string compaer strings in java compare string value strings string comparison in java comparison between two strings check if string equeals string if string java java check strings for equality compareto method in java java compare two string equal check if strings arent ewual java using string with compare in java java same string value how to campare to string in java function to see if a strings content is equal to another strings content if else string comparison in java compare string java example Y should nt we compare number in string java compareTo in java can you compare 2 strings objects using > java if check string compare 2 string in java java error equals 2 same strings compareto between strings java string coparison jkava how to compare 2 strings in java compare string value java comparison betwwen strings java comparing strings with == java compare strings different check if strings are different java how to compare 2 strin java if compare strings comparing the begining of string values java java how to compare two string java check if strings are equal can you use == to compare strings in java Create a program that takes in two words, check for equality ignoring the cases, if the words are equal the print the word in java Write a program to compare the strings given below, String 1 should be compared with all the other strings (5) Write a program to compare the strings given below, String 1 should be compared with all the other strings checking if strings are equal java compare equality of two strings in java how to equal to string how do strings compare java string equal to string compare using == check if string equal in java check if two strings are the same java java string equals 1 or 2 string compre java String values are compared using '!=', not 'equals()' check string equality comparing strings with == in java see if two strings are equal java compare sring values java string to string test java how to check if a string is == to a different stirng java jhow to compare strings in java Which of the following are use to compare a String value? how to compare 2 sTRING java compare string equal or not how to check string in java how toi compare strings in java check whether two strings are equal or not in java java equal strings java comparing 2 strings how tocheck if both strings are equal in java inbuilt function to compare two strings in java java compare strings by value compare 2 string in java explain comaprinf two strings using boole an java how to compair string in if java check values of two strings are the same java check values of two strings are equal test if strings are equal java how to compare tow strings in java Comparing String Objects java checking sting egality between strings java comparing 2 string are this strings equal jaba compare stirng == checks for java strings how to compare tring in java how java compares strings by default how to compair string values in string compare twostring in java check equality of string java if string in java how to compare a string to a string in java difference in strings value comparing strings in java with == check if string equal to string java how to to check string == in java java same string java comparing to strings check if string equals string[] java how to check the equality of string data member to another data member in java ode to compare strings in java compare two strings in java using inbuilt fun comparison operator for string in java what is equals() method of comparing strings for if else in java compare between two strings in java string .compered java check if 2 strings match compare method in java for two strings string1 == string2 java can strings be compared with == in java equalsto java java comparing two string strcmp in java compare text ja comparing 2 string give false compare string to string java equals method to compare names in java how to compare java strings comparing string in java if string and string are different java string comparation How do i compare a string name with four other string names in java check if strings equal each other java if string equals string java how to compare 2 strings java best way to compare strings java how are strings compared and string java if java sring compare how to compare string how to comapre two Strings in java how to compare strings in jaa most reliable way to compare two strings java compare to strings in javastring if with string java verify 2 string are equal java equality string in if in java equality string in java equality if string in java java most reliable way to compare two strings Write an application that compares two strings that a user inputs from the command line test whether strings match java see if strings equal in java Java two string equlaity matching two strings code how to check string string equals java how to check 2 strings are equal in java java check if string is equal to another string can i use == to compare strings in java where to compare two strings compare String in jvav string comp java how to compare string in if using java Write a Java program to read two strings from command line argument and check the equality of two string using string function. comparing string object in java how to check whether two strings are same in java how to compare 2 strings check equality in java how to compare string with number in if statement in java compare two string objects in java java comapre two strings How to compare if two strings are simular how to compare stirngs java how to compare string values in jva java compare strings equal how to compare two strings if its matching or not in java comapring string with the same lenght java match string in java check string equality in java are strings comparable in java how to compare two numeric strings in java java string comparrison java method to equal two strings verify string with 2 variables java === between two strings test strings equal java compare stirng in java string comparison in jav if string[2] == "-" testing string equality java java compare strins showing two strings equal in java how will you compare String values in java java test if 2 strings equal how to check if two strings are equal in java which is the most reliable expression for testing where the value of two string variable are the same ? string compare java == 2 string not campare in java compare 2 strings and print updated one java check if sting is same java string if equals .2% java in string java if statement equals if string equals if i have the same string string comparison java string == string comparing two string == java how to compare to string in java same string compare string to string[] check if string equals java compare strings use == check if 2 string are equal java string method to compare two strings if string==" " COMAPRE TWO STRINGS java equating two strings in java same string not equal java create equal strings check if a string equals java can you cmopare strings with > compare one string to another compare to in string in java java compareto two strings how to compare string[] in java how is strings compared in java comparison of strings in java how to check if two string aare the same in java java compare 2 strings for equality how to check if string equals in java in if statement how to check if string equals in java how to do string comparison in java how to compare strings in ajva check two strings are similar or not how java compare strings if statement string equal java which method is used in string to compare string in java compare function for string in java string compare of data how to compare the value of two strings in java how to compare with a " in java != string java compare two string equal or not come 2 string in java Text comparison in java compare strings with == java comparestrings java how to compare to strings how to compare the strings in java java check if strings are the same string 1 == string 2 method used to compare two strings in java string1.equals(string2) java how to compare string literal in java compare string check string value in java java if string java function compare two strings if 2 string match how to check if an object equals a string in java if (String == "") java how to compare 2 strings? java string != java check string how to check if string is same java string operators used to compare with string java check if string is similar how to check if two strings are equal two strings equal java how to compare the two strings in java how to compare the two strings compare two strings using boolean function in java =! for string java compare two string java how ot compare string in java string.equals(new string compare 2 strings java how to make a string equal another string java if string == string java how to check if the two strings are same in java compare 1 value of a string to each other value in the string java compare elements of a string java java compare two strings example equate strings java comparing two strings in java two string are equal or not java method check if two strings are equal match two string string comparisons java string equals another string how to compare value of two strings in java string 2 strings are equal or not how to compare 2 binary strings in java compare to stringin java equals method to find if 2 strings are equal how to compare words from given string in java to check if two strings are equal in java string is equal java compare operator string java equals in java string values are compared using '==' not 'equals()' comparing 2 strings compare 2 string java check string equal in java how to comapre string in java comparing two strings equals compare string how to know if String is the same java compare string is java java check if 2 strings are equal how to check if two strings are equal javasc compare two strings ljava compare strings check if two strings are equal in java if string equal to java check value of 2 strings java java compare a string check if two strings are same in java method to check string equality java how to check if strings are the same value string compare javac++ final compare strings in java compae stirng java comparing 2 string in java compare strings meaning java check string equality java check if 2 string are eaqul check if 2 character strings are identical java compare length of two strings java java string comparison if comparsion for strings java how to compare two strings string conparision in java String values are compared using '==', not 'equals()' equality of strings compareig 2 string java how to compare two string in java java use != compare string check if two stringsare equal java check two strings are equal comparing names in JAVA how to compare 2 string == in java how to compare 2 string in java ccopmaring string in java java compare to strings compare 2 strings in java compare tp strings java compare two strings string comparison java java if string equals compare two strings in java comparing two string values in java less or more compare to strings in java comparing strings in java to compare string in java comparing two string java string.compare java check equality of string in java compare two stringa in jV compare two string in java == between 2 strings in java java comparing strings how to compare two strings in java compare string in java compare strings [] java string compare compare string using com if two strings are equal java how to comparer srings in java how to chcek String in java comparing strings if st java check if 2 strings are equal java checking string equality in java how to compare one string to another in java comparing to string in java compare 2 strings string comparison in java equal 2 strings java how to compare strings how to compare strings java how to check if strings are equal in java java string comparason how to compare string in java how to compare a string evaluate 2 strings To compare two String Objects: java compare string java compare two strings how to check if a string is equal to another string in java java how to compare string values compare strings java check strings in java java check for two equal strings compare a part of string in java string compare in java how to use string compare in java java language check if two strings are equal compare two strings java comparing 2 strings in java java string equal to string compare string java java compare strings how to compare strings in java comparing strings java java how to compare strings
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source