Java Program to put value to a Property list


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

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 30-Jul-2019

221 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements