Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Sorting question  RSS feed

 
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 ]
 
Ranch Hand
Posts: 1067
2
IntelliJ IDE Java Spring
  • 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
Boost this thread!