Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Java in General and the fly likes ordering values in Arraylist Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "ordering values in Arraylist" Watch "ordering values in Arraylist" New topic
Author

ordering values in Arraylist

Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 483

Hi Guys ,

i got an ArrayList contains these values

but the values are messed up , i wanna order them to be in this order


Any ideas to achieve this ?


Thanks,
Sherif
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3429
    
  12
There are methods for sorting Lists in the Collections class


Joanne
Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 483

Joanne Neal wrote:There are methods for sorting Lists in the Collections class


but this mentioned in the documentation
Sorts the specified list into ascending order, according to the natural ordering of its elements
so this will not make it in the order i need above ..
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19653
    
  18

Then check the other sort method, which takes a java.util.Comparator. Implement your own Comparator class that does the sorting for you.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3429
    
  12
Sherif Shehab wrote:but this mentioned in the documentation
Sorts the specified list into ascending order, according to the natural ordering of its elements
so this will not make it in the order i need above ..


Note that I said there are methods for sorting. Try taking a look at the other one.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38007
    
  22
That looks like a tree; maybe you should to work out how to associate a FinancialStatus object with a List<FinanceStatus>.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: ordering values in Arraylist
 
Similar Threads
Derby Embedded Database: errors in connection code
Removing multiple if conditions
Many-to-many probelm help
Initializing and adding to an ArrayList
Unable to understand the setAttribute in java