a- /*
- Properties是Hashtable的子类
- 也就是说它具备map集合的特点。而且它里面存储的键值对都是字符串
- Preperties是集合中和I0技术相结合的集合容器
- 该对象的特点是,可以用于键值对形式的配置文件,而且不需要范行
- */
- import java.util.*;
- import java.io.*;
- class PropertiesDemo
- {
- public static void main(String[] args)
- {
- setAndGet();
- System.out.println("Hello World!");
- }
- public static void sop(Object obj){
- System.out.println(obj);
- }
- public static void setAndGet(){
- Properties prop = new Properties();
- //设置元素
- prop.setProperty("hah","12");
- prop.setProperty("heh","20");
- prop.setProperty("hih","20");
- //获取
- sop("hah:"+prop.getProperty("hah"));
- sop("heh:"+prop.getProperty("heh"));
- sop("prop:"+prop);
- //获取全部,遍历
- Set<String> names = prop.stringPropertyNames();
- /*
- for(String s:names)
- {
- sop(s+":"+prop.getProperty(s));
- }
- */
-
- for(Iterator<String> it = names.iterator();it.hasNext();){
- String s = it.next();
- sop(s);
- }
- }
- }
复制代码
|
|