java - 如何按顺序对属性文件值进行排序?

标签 java properties set

我有一个名为 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/

相关文章:

java - wsimport 使用额外的下划线错误地生成枚举类型

java - 从文件夹加载纹理

c# - 具有用户可配置属性 "visibility"的对象

C++ STL 按值设置删除

algorithm - 如何计算包含一组字符的所有可能组合的排序列表中字符串值的索引?

java - Http 请求中的错误消息

java - Android Room Java 内连接与计数

c# - 可以在类中存储 LINQ 查询吗?

java - JSP Web 项目中找不到 Config.properties 文件

python-3.x - Python - 更新集合