Topic: 哪位有可排序的Properties类?

  Print this page

1.哪位有可排序的Properties类? Copy to clipboard
Posted by: jfml
Posted on: 2003-07-11 17:05

java自己的Properties类是散列数据的

我想根据.prp文件中的kv出现顺序

得到相应的集合

哪位有类似源码share一下

谢谢

2.Re:哪位有可排序的Properties类? [Re: CrazyJavar] Copy to clipboard
Posted by: greenflute
Posted on: 2003-07-17 12:00

You should make sure whether the key or the value is what you want to sort, then you may dump all your properties into an ArrayList, then use Collections.sort(List, Comparator) method to sort it (do not forget to implement your own Comparator).

3.Re:哪位有可排序的Properties类? [Re: greenflute] Copy to clipboard
Posted by: ditty
Posted on: 2003-07-17 13:36

可以自己实现一个嘛!比如用两个Vector (或ArrayList),分别保存Key和Value.

只要实现两个列表的同步就可以了。

4.Re:哪位有可排序的Properties类? [Re: CrazyJavar] Copy to clipboard
Posted by: frankwg
Posted on: 2003-07-18 12:37

try following code snippet:

package scrapbook;

import java.util.Properties;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Map;
import java.util.TreeMap;
import java.util.Iterator;

public class OrderedProperties {

public static void main(String[] args) {
Properties prop = new Properties();
try {
prop.load(new FileInputStream("test.properties"));
}
catch (IOException ex) {
System.out.println("I/O Error!!! Probably \"test.properties\" not found.");
}

Map orderedProp = new TreeMap(prop);

Iterator itr = orderedProp.entrySet().iterator();
while (itr.hasNext()) {
Map.Entry entry = (Map.Entry) itr.next();
System.out.println(entry.getKey() + "=" + entry.getValue());
}
}
}


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923