美文网首页工作生活
Java Properties 类

Java Properties 类

作者: 龍飝 | 来源:发表于2019-07-03 13:55 被阅读0次

    import java.util.*;
    public class PropDemo {
    public static void main(String[] args) {
    Properties capitals = new Properties();
    Set states;
    String str;

        capitals.put("Illinois", "Springfield");
        capitals.put("Missouri", "Jefferson City");
        capitals.put("Washington", "Olympia");
        capitals.put("California", "Sacramento");
        capitals.put("Indiana", "Indianapolis");
    
        // 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();
    
        // look for state not in list -- specify default
        str = capitals.getProperty("Florida", "Not Found");
        System.out.println("The capital of Florida is " + str + ".");
    }
    

    }

    相关文章

      网友评论

        本文标题:Java Properties 类

        本文链接:https://www.haomeiwen.com/subject/plpqhctx.html