How to sort properties in Java

· 1 min read

Sometimes you have to deal with Properties files in Java. And sometimes you have to sort the entries based on the keys stored on the file, and you realized that is not so easy using default Properties class from java.util package.

This occurs because java.util.Properties extends java.util.Hashtable, which does not define a predictable sort order for keys or values.

For this situation, you can use the SortedProperties class to get entries sorted by key alphabetically.

Author avatar

Marcelo Rodrigo

Apaixonado por viagens, software e bicicletas

Search pages

Loading search index...

No results found. Try a different search term.

↑↓ navigate Enter select Esc close