Java Collection How to - Put value to a Property list








Question

We would like to know how to put value to a Property list.

Answer

   /* w  ww.j a  v a2  s  . c om*/

import java.util.Properties;
import java.util.Set;

class PropDemo {
  public static void main(String args[]) {
    Properties capitals = new Properties();

    capitals.put("Illinois", "Springfield");
    capitals.put("Missouri", "Jefferson City");
    capitals.put("Washington", "Olympia");
    capitals.put("California", "Sacramento");
    capitals.put("Indiana", "Indianapolis");

    Set states = capitals.keySet();

    for (Object name : states)
      System.out.println(name + " / " + capitals.getProperty((String) name));

    String str = capitals.getProperty("Florida", "Not Found");
    System.out.println("The capital of Florida is " + str + ".");
  }
}