码迷,mamicode.com
首页 > 其他好文 > 详细

LinkedHashMap,TreeMap和Hashtable子类Properties

时间:2014-12-07 21:40:56      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   color   使用   sp   on   文件   div   

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

LinkedHashMap,TreeMap和Hashtable子类Properties

标签:style   blog   io   color   使用   sp   on   文件   div   

原文地址:http://www.cnblogs.com/yjtm53/p/4149898.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!