Easy sort a list of SelectItem's

Posted on by Kim

Easy way to sort a Collection for e.g. dropdown.

Collections.sort(<Collection of SecletItem's>, new SecletItemComparator());

// Inner class
public class SecletItemComparator implements Comparator {
@Override
public int compare(SelectItem s1, SelectItem s2) {
return s1.getLabel().compareTo(s2.getLabel());
}
}

1 comments:

Himalay says:

I Dont think we need the override tag. Worked for me...thank you.