This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Sorting question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Sorting question" Watch "Sorting question" New topic
Author

Sorting question

Lenin Chada
Greenhorn

Joined: Mar 10, 2003
Posts: 3
Hi,
can any body please give me an sample code to sort on 2nd, 3rd, or 4th item
Array.sort(A) is sorting on first item
I written this comparator code
class StringCompare2 implements Comparator {
public int compare(Object o1, Object o2) {
String s1 = (String)o1;
String s2 = (String)o2;
return s1.compareTo(s2);
}
}

A[1] = [xx, aa, yy, 22, zz]
A[2] = [aa, xx, bb, 33, cc]
A[3] = [dd, yy, cc, 11, xx]
I want sort on 3 rd item in that array
Result like
A[1] = [aa, xx, bb, 33, cc]
A[2] = [dd, yy, cc, 11, xx]
A[3] = [xx, aa, yy, 22, zz]
thanks in advance
Typo in title corrected -BFG
[ March 10, 2003: Message edited by: Barry Gaunt ]
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 984

It seems like you need to send the third element of the array to be compared, and that would be A[1][3] and A[2][3] and A[3][3], ...


Please ignore post, I have no idea what I am talking about.
 
 
subject: Sorting question
 
Similar Threads
sorting an array of integers - a problem.
Problem in binarySearch()
please explain the output?
JTable colored rows or columns
BinarySearch Doubt