package config;import java.util.Iterator;
import java.util.Properties;
import java.util.Set;/*** 这个类演示了如何使用Properties类来存储和访问键值对。* Properties类继承自Hashtable,因此它可以用来存储键值对数据,且支持同步。*/
public class ProDemo {Properties p = new Properties();public static void main(String[] args) {Properties capital = new Properties();Set state;String str;capital.put("Illinois", "Springfield");capital.put("Missouri", "Jefferson City");capital.put("Washington", "Olympia");capital.put("California", "Sacramento");capital.put("Indiana", "Indianapolis");state = capital.keySet();Iterator it = state.iterator();while(it.hasNext()){/*注意:因为iterator对象在创建的时候,其内部的指针指向集合中第一个元素之前,当首次调用next()方法的时候 指针会移向第一个元素 并返回该元素*/str = (String) it.next();System.out.println("The capital of"+str+"is"+capital.getProperty(str)+".");}System.out.println();str = capital.getProperty("Florida","Not Found");System.out.println("The capital of Florida is"+str);}}