This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes Sorting Asciibetically 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 Asciibetically" Watch "Sorting Asciibetically" New topic
Author

Sorting Asciibetically

Lexy Yang
Greenhorn

Joined: May 07, 2012
Posts: 2
How do you sort strings asciibetically?
Pondurai Singh
Ranch Hand

Joined: Jun 27, 2011
Posts: 32
Example program Sort an array of ASCII strings into ascending order
Reference: oreilly.com/9781565923713/


Software Developer, Oracle Java Certification Training Labs at EPractize Labs
OCPJP 7 | OCAJP 7
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

No offense, but I would never use anything from that code:
1) That Comparer interface is exactly the same as the old non-generic java.util.Comparator interface.
2) That Comparable interface is exactly the same as the old non-generic java.lang.Comparable interface.
3) That sorting functionality already exists in java.util.Arrays. To sort in reverse order, you can use one of the two reverseOrder methods in java.util.Collections.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32654
    
    4
Rob Spoor wrote: . . . To sort in reverse order, you can use one of the two reverseOrder methods in java.util.Collections.
Or you write a ComparatorNow that is really complicated, isn’t it
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

That compare method is 100% identical to the implementation of reverseOrder(). That's also a singleton which makes it slightly more efficient - no matter how many times you call the method, only one object is created.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32654
    
    4
I hadn’t noticed that reverseOrder creates a Comparator rather than reversing the list
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Sorting Asciibetically
 
Similar Threads
String Ordering Asciibetically