首先,设置属性并用于put()
将值放入属性列表-
Properties p = new Properties(); p.put("India", "1983"); p.put("Australia", "1987"); p.put("Pakistan", "1992"); p.put("Srilanka", "1996");
现在,显示属性键和值对-
Sets = p.keySet(); for (Object record: s) System.out.println(record + " / " + p.getProperty((String) record));
import java.util.Properties; import java.util.Set; class Demo { public static void main(String args[]) { Properties p = new Properties(); p.put("India", "1983"); p.put("Australia", "1987"); p.put("Pakistan", "1992"); p.put("Srilanka", "1996"); Sets = p.keySet(); for (Object record: s) System.out.println(record + " / " + p.getProperty((String) record)); } }
输出结果
Srilanka / 1996 Pakistan / 1992 Australia / 1987 India / 1983