LinkedHashMap,TreeMap和Hashtable子类Properties

1 LinkedHashMap:使用链表去维护添加进Map中的顺序。故遍历Map时,总是按照添加的顺序遍历

2 按照添加进Map中的元素的key的制定属性进行排序。要求:key是同一个类的对象。 分为:自然排序vs定制排序。代码和TreeSet基本一样

3 Hashtable:古老的实现类,不建议使用。Properties:常用来处理属性文件,键和值都是String类型的

例如:

public class TestProperties{
@Test
     public void test1()throws FileNotFoundException,IOException{
       Properties pro = new Properties();
       pro.load(new FileInputStream(new File("file1")));
       String s1 = pro.getProperty("aaa");
       String s2 = pro.getProperty("aaa");
       System.out.println(s1+"\n"+s2);
}
}

file1:

aaa = 234
bbb = 242
ccc = 231

结果:

234

234

posted on 2014-12-07 21:23  追梦的小屁孩  阅读(165)  评论(0编辑  收藏  举报