当前位置:   article > 正文

java 动态属性排序,如何在java中对属性进行排序?

java 动态属性排序

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.

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/557985
推荐阅读
相关标签
  

闽ICP备14008679号