我有一个名为 sample.properties
的属性文件,其值如下所示,
a=A
b=B
c=C
我通过ResourceBundle
获取属性值并将其存储在如下所示的集合中,
private Set<Entry<Object, Object>> sampleSet = null;
for(Properties properties:sampleProperties){
sampleSet = properties.entrySet();
}
但是当我在 UI 中显示属性文件时,输出如下所示
c=C
a=A
b=B
这不符合顺序。
最佳答案
Set
不会维持键的顺序,如果想维持顺序,可以使用TreeSet
private TreeSet<Entry<Object, Object>> sampleSet = new TreeSet<Entry<Object, Object>>();
for(Properties properties:sampleProperties){
sampleSet.addAll(properties.entrySet());
}
关于java - 如何按顺序对属性文件值进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31045812/