• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Please help!! simple question

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi everyone,
could you please tell me the way to sort the elements in an awt.list.i'm making a chat program and adding and removing the user as they entered and leave the chat room.Please tell me how i can sort these names.
i'll be highly obliged.
asheet anand
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've never used an awt.List before, but I can make a suggestion based on the API.

There isn't a constructor for the list that allows you to give it a pre-sorted list, but instead you'd have to use .add(String item, int index)

Doing it this way, you'd need to ensure that every time you go to insert a name, that you are inserting it in the right place. Sort of like linked lists. You could use the getItems() which returns an array of Strings. Then you can compare each String in that array with the String you want to insert. As soon as you find that the current array String (at [index]) is alphabetically 'after' the one you want to insert.. then use [index - 1] as the parameter to the add method like: .add(String nameToInsert, int index -1)

Something I just thought of... the API doesn't specify if the item that is currently at that index gets removed, or if everything bumps down one (like in a Vector). If it doesn't get bumped down, then you will need to implement this bump-down behaviour yourself.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
TO ,
sort the list you get the user names of the chatters from the database presorted.And your work is to remove all elements from the list and add the new members as fresh items.
Jaggi.
------------------
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic