Archives for 

Map

Classes that implements Map interface is explained in this category

Properties in Java

Properties  in Java

Properties in Java is a subclass of  Hashtable.It stores String values against String keys.The contents of a  Properties object  can be directly saved to  a file and a properties file can be  directly  loaded to a properties object.Since Properties  is a subclass of Hashtable,  the methods put() and putAll()  is applicable to Properties too. These methods allow the insertion of non-String keys as well as values.So the use of put() and putAll() is highly discouraged.

The program shown below reads a properties file and displays the key value pairs.The appending few more keys.The existing myfile.properties file is in C:/tmp folder.

 

Now see the code shown below.

Output

Contents of properties

Key : TN ; Value : Chennai

Key : Goa ; Value : Panaji

Key : Kerala ; Value : Trivandrum

Reading is over

Added  new properties

Contents of properties

Key : Karnataka ; Value : Bangalore

Key : TN ; Value : Chennai

Key : Goa ; Value : Panaji

Key : Bihar ; Value : Patna

Key : Kerala ; Value : Trivandrum

Reading is over