Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

order list returned by other api

Posted on 2006-06-09
6
Medium Priority
?
229 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1600 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 26

Assisted Solution

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

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

Assisted Solution

by:ksivananth
ksivananth earned 1600 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 400 total points
ID: 16880195
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

610 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