> Thanks I got it.
> toLowercase() and toUppercase() are
> case-Sensetive..there is compareToIgnoreCase()
In other words, use either toUpperCase() or toLowerCase() on both Strings when you use compareTo() and you are effectively comparing them while ignoring case. i.e.
String a = "Hello is anybody in there?";
String b = "The lights are on, but nobody's home.";
if (a.toLowerCase().compareTo(b.toLowerCase()) != 0) {
System.out.println("The elevator does not go all the way to the top floor.");
}
> Thanks
> I have a string list like this
>
>poke Mon, Leoparde, Stuart, gia Jo
> ere Mon,Leoparde,stuart and jo are lastnames ...
> and I want them to get compared and sorted
> There is compareToIgnoreCase() but it is not helping.
How are you using it? If you are trying to use the Collections.sort or Arrays.sort methods, you need to use the version that takes a Comparator and pass in String.CASE_INSENSITIVE_ORDER.
> I am using arrays.sort..and i am not getting any
> compile error while using compareToIgnoreCase()
sort doesn't use that method by default. You need to use a Comparator if you are not now.
> My problem is some names are like "gia Jo" (as one
> string) and i want just to compare and sort just
> "Jo"
That's a completely different problem. You need to parse the Strings into the portions you want to compare and there's no way for anyone to tell you how without a clear understanding of what data is possible and what your desired results are.