Charles Bell
Posts: 519
Nickname: charles
Registered: Feb, 2002
|
|
Re: sorting in collection alphabetically problem!
|
Posted: May 10, 2003 9:50 AM
|
|
you have to write the code for your own Comparator interface which implements the following methods:
?int compare(Object?o1, Object?o2)
?boolean equals(Object?obj)
Then use the static Collections sort(Comparator) method with an instance of a class that implements it.
I would write a string of characters which reads from lowest to highest in sort order such as:
String sortString = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ");
Use the position of a character in this string to determine a comparison of two strings iterating through eaxh character until the end is reached or an inequality is reached. if the end is reached, then the two strings are equal return a 0, if less than return -1, is greater return +1 or something like that.
Since you did not mention other characters such as the numbers and other keyboard characters and how they compare to the above sort string, I can't help any further.
|
|