import java.util.Enumeration;
import java.util.Properties;
public class props {
public static void main(String []args)
{
Properties p =new Properties();
p=System.getProperties();
System.out.println("Properties details");
Enumeration<?> e = p.propertyNames();
while( e.hasMoreElements())
{
String s = (String)e.nextElement();
System.out.println(s+"--------"+p.getProperty(s));
}
}
}
Here the p.PropertyNames() will return a enum with all distinct keys. and <?> means the enum can have key as any thing like object string, int etc
After getting the enums we are just looping and getting single key at a time and then getting the corresponding value.
Enjoy . Happy Coding
We can substitue System.out.println("Properties details");
ReplyDeleteEnumeration e = p.propertyNames();
while( e.hasMoreElements())
{
String s = (String)e.nextElement();
System.out.println(s+"--------"+p.getProperty(s));
}
}
part with the following single line:
p.list(System.out);