赞
踩
I have a Properties variable 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.Properties extends java.util.Hashtable which 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.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。