compare strings in java
int str1.compareTo(String str2)// Java program to Compare two strings
// lexicographically
public class GFG {
public static void main(String args[])
{
String string1 = new String("Geeksforgeeks");
String string2 = new String("Practice");
String string3 = new String("Geeks");
String string4 = new String("Geeks");
String string5 = new String("geeks");
// Comparing for String 1 != String 2
System.out.println("Comparing " + string1 + " and " + string2
+ " : " + string1.equals(string2));
// Comparing for String 3 = String 4
System.out.println("Comparing " + string3 + " and " + string4
+ " : " + string3.equals(string4));
// Comparing for String 4 != String 5
System.out.println("Comparing " + string4 + " and " + string5
+ " : " + string4.equals(string5));
// Comparing for String 1 != String 4
System.out.println("Comparing " + string1 + " and " + string4
+ " : " + string1.equals(string4));
}
}
if (aName.equals(anotherName))
{
System.out.println(aName + " equals " + anotherName);
}
else
{
System.out.println(aName + " does not equal " +anotherName );
}
Also in Java:
- how to make a new arraylist java
- numberformatexception
- inputstream to string java
- import scanner
- how to know when user is done typing android
- Unrecognized option: --version Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit.
- convert char to string java
- java hello world
- set html text android java
- runtime java examples
- one line if statement java
- java iterate through map
- compile java
- isnumber java
- compare strings in java
- intellij replace all
- java math.random
- java string reverse
- take a value from keyboard java
- taking string input in java
- java execute for cycle parallel thread
- jbutton set background transparent
- Failed to apply plugin [class 'com.google.gms.googleservices.GoogleServicesPlugin']
- floor in java