I have a Properties object and sometimes I need to add other Properties to it.
Properties myBasicProps = this.getClass.getResourceAsStream(MY_PROPS_PATH);
...
Properties otherProps = new Properties();
otherProps.load(new StringReader(tempPropsString)); //tempPropsString contains my temporary properties
myBasicProps.putAll(otherProps);
I want to sort myBasicProps after this. I don’t want to get all keys and values, sort them with Collections.sort() and then put it all to a new object. Is there a better way?
No,
java.util.Propertiesextendsjava.util.Hashtablewhich doesn’t define a predictable sort order for keys or values.You could try dumping all values into something like
java.util.TreeMap, which will impose a natural ordering on your keys.