java membandingkan string abjad

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
} 
Brave Buffalo