• Post Reply Bookmark Topic Watch Topic
  • New Topic

need algorithm for arranging  RSS feed

 
Christian Nash
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

How do i arrange an arraylist having many words into an arraylist which has the longest word as its first word and the shortest word as its last element?
 
Alana Sparx
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I think you need to write a comparator, then pass this to thje Collections.sort() method.

Javadoc for this is
Java Sun
 
Christian Nash
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,


I think you need to write a comparator, then pass this to thje Collections.sort() method.

Collections.sort() method is used for sorting alphabetically. So i don't think it will work
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ashwin Kudwa:
hi all,


I think you need to write a comparator, then pass this to thje Collections.sort() method.

Collections.sort() method is used for sorting alphabetically. So i don't think it will work


Unless you pass a Comparator to it as Alana suggested.
 
Alana Sparx
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cheers J

I *knew* I was on the right track.....
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!