• Post Reply Bookmark Topic Watch Topic
  • New Topic

Sort an arraylist by name in alphabetical order  RSS feed

 
Ranch Hand
Posts: 65
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have pipespace delimited text file that's opened by file chooser and then stored into an arraylist. I need to sort the arraylist by name alphabetically. This is what I've tried, but it's not even close.





Following this, I am to somehow get this arraylist to show up in a JList, but have no idea how to even begin that I've got a GUI window that shows up, and only have a very vague idea of how panels work, but that's about it. My instructor kinda shoehorned this project in at the last minute due to poor class time management and gave minimal instruction at best. I just want to get through this class so that it doesn't tank my GPA, and switch majors. I'm done with CS. I may continue coding and work on learning more on my own, but the academic side of things feels a lot like watching CSPAN while getting a root canal.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose you should try like this.



Hope this helps.
 
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rajith Pemabandu's code can be simplified if you don't need a case insensitive sort: And you can eliminate the ALPHABETICAL_ORDER method.

Some other notes on the code: contactList should be initialized with a generic:
The method name ALPHABETICAL_ORDER should be alphabeticalOrder by convention.
 
Knute Snortum
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Following this, I am to somehow get this arraylist to show up in a JList, but have no idea how to even begin that I've got a GUI window that shows up, and only have a very vague idea of how panels work, but that's about it. 

This should be another post in this forum.
 
Master Rancher
Posts: 2045
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to sort on the basis of case_insensitive, and then on natural order, java 8 makes this a little easier, for instance:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!