Java Program to put value to a Property list

Java 8Object Oriented ProgrammingProgramming

First, set properties and use put() to put value to property list −

Properties p = new Properties();
p.put("India", "1983");
p.put("Australia", "1987");
p.put("Pakistan", "1992");
p.put("Srilanka", "1996");

Now, display the properties key and value pairs −

Sets = p.keySet();
for (Object record: s)
System.out.println(record + " / " + p.getProperty((String) record));

Example

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));
   }
}

Output

Srilanka / 1996
Pakistan / 1992
Australia / 1987
India / 1983
raja
Published on 24-Apr-2019 09:10:51
Advertisements