Answers for "java compare two strings alphabetically"

2

java compare strings alphabetically

String a = "HYRE"; 
String b = "AGNYG";  

int compare = a.compareTo(b);  

if (compare < 0) {  
    //a is smaller
}
else if (compare > 0) {
    //a is larger 
}
else {  
    //a is equal to b
}
Posted by: Guest on December-11-2020
0

compare two character alphabetically java

return Character.toLowerCase(ch1) < Character.toLowerCase(ch2);
Posted by: Guest on October-30-2021

Code answers related to "java compare two strings alphabetically"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language