Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Use Comparator to sort more than one column  RSS feed

 
Wiyanto Ngasinur
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using comparator interface to sort list of object.
Problem comes when there are more than one column to sort. For example :
I've unsorted tables :
Id|Department|Sub Department
1 Test Sub Test
2 Abap Sub Abap2
3 Abap Sub Abap1

How do i have two sort, Department then sub department. It become :
Id|Department|Sub Department
3 Abap Sub Abap1
2 Abap Sub Abap2
1 Test Sub Test

I'm implementing Comparator interface :


but it doesn't worked. Any idea ?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's more like



You compare using the second key only of the first keys are equal.
 
Wiyanto Ngasinur
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, you save me a lot time.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!