Skip to Content
avatar image
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 comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • avatar image
    Former Member
    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 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