Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sorting question

 
Lenin Chada
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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], ...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic