`

Properties 示例

    博客分类:
  • Java
 
阅读更多

/*

为了更大的灵活性,当构造一个属性(Properties)对象时,指定一个默认的属性列表。如果在主列表中没有发现期望的关键字,将会搜索默认列表。

*/

//Use a default property list.
import java.util.*;
class PropDemoDef{
 public static void main(String[] args)
 {
  Properties defList = new Properties();
  defList.put("JiLin","ChangChun");
  defList.put("ShanDong","JiNan");

  Properties capitals = new Properties(defList);
  Set provinces;
  String str;

  capitals.put("JiangSu","NanJing");
  capitals.put("LiaoNing","ShenYang");
  capitals.put("ShanXi","XiAn");
  capitals.put("HeBei","ShiJiaZhuang");

  //show all provinces and captials in hashtable
  provinces = capitals.keySet();  //get set-view of keys
  Iterator i = provinces.iterator();

  while(i.hasNext()){
   str = (String)i.next();
   System.out.println("The captial of " + str + " is " + capitals.getProperty(str) + " .");
  }
  System.out.println();

  //JiLin will now be found in the default list.
  str = capitals.getProperty("JiLin");
  System.out.println("The captial of  JiLin is " + str + " .");
 }
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics