集合

它们中的叛徒是:Vector和Stack、Hashtable和Properties这两对父子,它们都是线程安全的,也是同步的。

说说Properties比较有别于其它的集合的用法吧:

Properties可以与io流结合使用:

public void load(Reader reader)

public void load(InputStream inStream)

 

如:load方法可以实现properties配置文件中的键值对以流的方式加载到Properties集合中:

 

//新建一个test对象

Test test = new Test():

//新建一个Properties对象

Properties prop = new Properties();

//获得流对象,111.properties与Test类同一个包下

InputStream in =test.class.getClassLoader.getResourseAsStream(“111.properties”);

//把111.properties中键值对读取到prop里

prop.load(in);

 

   也可以把集合中的数据存储到文本文件中

   public void  store(Writer writer,String comments)

   publicvoid store(OutputStream out,String comments)




posted @ 2021-10-16 23:39  chencaijie  阅读(39)  评论(0)    收藏  举报