Solved

order list returned by other api

Posted on 2006-06-09
6
175 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
Comment Utility
you have to use a comparator to sort this
0
 
LVL 26

Expert Comment

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

Accepted Solution

by:
ksivananth earned 400 total points
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 26

Assisted Solution

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

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

Assisted Solution

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

will sort students object based on name!
0
 
LVL 30

Assisted Solution

by:mayankeagle
mayankeagle earned 100 total points
Comment Utility
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Java 1603 Error 2 42
@SBGen Method 3 25
Where to store the queries for modification of table 4 25
Java JRE greater than 1.6 5 0
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.

743 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

17 Experts available now in Live!

Get 1:1 Help Now