Skip to Content
author's profile photo Former Member
Former Member

Sorting problem

I created a vector and I need to sort it by last name

is there any way somebody can help me to solve this problem

code is some what like this

Vector searchResult = new Vector();

for(int i=0; i<employeeIds.size();i++)

{

IUserFactory iUserFactory = UMFactory.getUserFactory();

try

{

logger.severe("user factory is :"+(String)employeeIds.get(i));

.

.

.

SearchResultBean searchResultBean = new SearchResultBean();

searchResultBean.setEmailAddress(iUser.getEmail());

.

.

searchResultBean.setLastName(iUser.getLastName());

searchResult.add(searchResultBean);

// I need to return the searchResult sorted by Last name

return searchResult;

}

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Feb 15, 2005 at 09:11 AM

    Hi TT,

    I would make a new class that extends SearchResultBean and implements Comparable to use Collections.sort(List).

    Another question, i would use ArrayList instead Vector due to performace, if you don't need a synchronized list (Vector).

    bye.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Better yet -- use variation

      java.util.Collections.sort

      (

      java.uitl.List,

      java.util.Comparator

      )

      supplying comarator that is aware how to compare IPrincipal objects.

      This way you can avoid creation of unnecessary classes.

      VS

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.