Makky Makky - 2 months ago 14
Java Question

Comparing strings by their alphabetical order

String s1 = "Project";
String s2 = "Sunject";


I want to compare the two above string by their alphabetic order (which in this case "Project" then "Sunject" as "P" comes before "S").
Does anyone know how to do that in Java?

Answer

String.compareTo might or might not be what you need.

Take a look at this link if you need localized ordering of strings.