propdemo.java~2~

来自「java2参考大全上的例子的源码和自己的理解.」· JAVA~2~ 代码 · 共 47 行

JAVA~2~
47
字号
package properties;

/**
 该程序的输出如下所示:
 The capital of Missouri is Jefferson City.
 The capital of Illinois is Springfield.
 The capital of Indiana is Indianapolis.
 The capital of California is Sacramento.
 The capital of Washington is Olympia.
 The capital of Florida is Not Found.
 */

// Use a default property list.
import java.util.*;

class PropDemoDef {
  public static void main(String args[]) {
    Properties defList = new Properties();
    defList.put("Florida", "Tallahassee");
    defList.put("Wisconsin", "Madison");

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

    capitals.put("Illinois", "Springfield");

    // Show all states and capitals in hashtable.
    states = capitals.keySet(); // get set-view of keys
    Iterator itr = states.iterator();

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

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

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?