我有一个 Properties
对象,有时我需要添加其他 Properties
到它。
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);
我想在此之后排序 myBasicProps
。我不想获取所有键和值,用 Collections.sort()
对它们进行排序,然后将它们全部放入一个新对象。有没有更好的办法?
原文由 shift66 发布,翻译遵循 CC BY-SA 4.0 许可协议
不,
java.util.Properties
扩展java.util.Hashtable
没有为键或值定义可预测的排序顺序。您可以尝试将所有值转储到
java.util.TreeMap
类的内容中,这将对您的键施加自然排序。