aspose file tools
The moose likes Java in General and the fly likes Sorting of Strings in a UserDefined Way Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Sorting of Strings in a UserDefined Way " Watch "Sorting of Strings in a UserDefined Way " New topic
Author

Sorting of Strings in a UserDefined Way

Sarita KShetty
Greenhorn

Joined: Nov 05, 2008
Posts: 4
Sorting of Strings in a UserDefined Way :

I have a Set of Strings in the order{This is the order in which sorting is to be done}
"Public","InternalUse","Confidential"
My requirement is that i Have to sort the column containing the above String Values in the order mentioned above.


For example: If I have
"Internal Use","Confidential","Public" as values in the column

After sorting it should be :


"Public", "InternalUse","Confidential"
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32688
    
    4
Can you create a Comparator which will support your sorting order?
Can you put your Strings as keys in a Map and return a Double which indicates the sorting order? Using a Double rather than Integer allows you to insert intermediate values later on.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Why not just send them to the page in that order?

Is there any other value associated with the strings?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16483
    
    2

Why not just use an enum with those three values?
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Sorting of Strings in a UserDefined Way
 
Similar Threads
table sorter
Table Sorting (I know it is a pain)
Sorting Complication
TableSorter and Selection gives problems
Problem while retrieving values from table