Sorting Hashtable Keys in Java

April 30, 2015

I wanted to sort the keys in a hashtable in Java, this can be done with the following code:

 private void process(Hashtable<String, String> pColumnsHash)
  {
    List<String> lColumnNames = new ArrayList<String>(pColumnsHash.keySet());
    Collections.sort(lColumnNames);

    Iterator<String> lColumnNamesIterator = lColumnNames.iterator();
    ...
  }

Tags: java hashtable sort