Solved

order list returned by other api

Posted on 2006-06-09
6
186 Views
Last Modified: 2010-03-31
my code is similiar to:

ArrayList a = otherAPI.searchStudent( "registered");

the a is a ArrayList containing the students registered, but I want to sort this list. I don't know how to do it, and I don't want to otherAPI to sort it on DB side, since I will sort list by different column in different situations.

thanks
0
Comment
Question by:keepworking
  • 5
6 Comments
 
LVL 26

Expert Comment

by:ksivananth
ID: 16874953
you have to use a comparator to sort this
0
 
LVL 26

Expert Comment

by:ksivananth
ID: 16874959
and Collections.sort( list, yourComparator ) ; will do the job
0
 
LVL 26

Accepted Solution

by:
ksivananth earned 400 total points
ID: 16874978
for e.g.,

class StudenComparator implements Comparator{

  private int on ;

  public StudenComparator( int compareOn ){
    on = compareOn ;
  }

  public int compare( Object obj1, Object obj2 ){
    Student s1 = ( Student )obj1 ;
    Student s2 = ( Student )obj2 ;

    if( on == 0 ){
      String name1 = s1.getName() ;
      String name2 = s2.getName() ;
      return name1.compareTo( name2 ) ;
    }else if( on == age ){
//and so on
    }
  }
}
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 26

Assisted Solution

by:ksivananth
ksivananth earned 400 total points
ID: 16874981
>>}else if( on == age ){

}else if( on == 1 ){ //age
0
 
LVL 26

Assisted Solution

by:ksivananth
ksivananth earned 400 total points
ID: 16875046
Collections.sort( list, new StudenComparator( 0 ) ) ;

will sort students object based on name!
0
 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 100 total points
ID: 16880195
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
wordappend challenge 8 143
Java and GPO 11 66
javap bin 2 25
servlet example issue 6 29
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now