枚举中的订单不匹配

亚什·瓦什尼(Yash varshney)

我正在使用枚举读取属性文件。假设我的属性文件中的值为lon2qaidxiat01.idx.local, master, 2015-02-13, 2015-02-28但是当我尝试使用读取相同内容时Enumeration,它会像一样随机读取2015-02-13,master,2015-02-28,lon2qaidxiat01.idx.local

下面是我的代码:

try {
    dbProperties.load(new FileInputStream("config/db.properties"));
    Enumeration enuKeys = dbProperties.elements();
    while (enuKeys.hasMoreElements()) {
        String key = (String) enuKeys.nextElement();
        String value = dbProperties.getProperty(key);
        System.out.println(key);
        paramList.add(key);
    }
    ...

请建议如何使用枚举顺序读取。

Aioobe

这是因为Properties仅仅是一个Hashtable,并不保证任何特定的排序。(无法解决此问题。在调用时,顺序丢失了dbProperties.load。)

如果排序很重要,请使用键/值对中的一个LinkedHashMap或一个List(并滚动您自己的加载例程)。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章