The Artima Developer Community
Sponsored Link

Java Answers Forum
sorting in collection alphabetically problem!

1 reply on 1 page. Most recent reply: May 10, 2003 9:50 AM by Charles Bell

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
ashwini

Posts: 1
Nickname: ashwini
Registered: May, 2003

sorting in collection alphabetically problem! Posted: May 8, 2003 4:22 AM
Reply to this message Reply
Advertisement
i have a collection very huge one with words with both uppaer and lower case
i want it to be sorted like small a then Big A then b B cC so on....
how do i acieve this
i need to sort the collection and view in a jsp page
any simple way to do it
urgently needed help


Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: sorting in collection alphabetically problem! Posted: May 10, 2003 9:50 AM
Reply to this message Reply
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.

Flat View: This topic has 1 reply on 1 page
Topic: Hash table, any ideas?? Previous Topic   Next Topic Topic: constructors

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use