sortSet

List sutil.sortSet ( Set set )
List sutil.sortSet ( Set set, boolean ignoreCase )
List sutil.sortSet ( Set set, Comparator comparator )

Description

Sorts the elements in a set into an ordered list.

Parameters

  • set The set whose elements should be sorted
  • ignoreCase (optional) True if case is irrelevant when sorting strings
  • comparator (optional) The Comparator used to compare objects in the set to determine order

Return Values

This method returns a sorted list of elements that are in the set.

Change Log

Version Description
5.5.26a Available in all editions.

Examples

Output all the values in a DataRecord in alphabetical order

 // Generally when a sorted set or map is needed, a data structure should be chosen that stores the values
 // in a sorted way, such as TreeSet or TreeMap.  However, sometimes the set or map is returned by a library
 // and may not have sorted values, although sorted values are needed.
 
 List keys = sutil.sortSet(dataRecord.keySet(), true);
 
 for(int i = 0; i < keys.size(); i++)
 {
   key = keys.get(i);
   session.log(key + " : " + dataRecord.get(key));
 }