1. Overview of properties
Properties: Property Collection Class . is a collection class that can be used in conjunction with IO streams.
Properties can be saved in a stream or loaded from a stream. each key and its corresponding value in the property list is a string .
Properties is a subclass of Hashtable , and the description is a map collection .
2. Properties as a map collection using
1 Packagecn.itcast_08;2 3 Importjava.util.Properties;4 ImportJava.util.Set;5 6 /*7 * Properties: Property Collection class. is a collection class that can be used in conjunction with IO streams. 8 * Properties can be saved in the stream or loaded from the stream. Each key and its corresponding value in the property list is a string. 9 * Ten * is a subclass of Hashtable, description is a map collection. One */ A Public classPropertiesdemo { - Public Static voidMain (string[] args) { - //use as a collection of maps the //The following usage is wrong, be sure to look at the API, if there is no <>, it means that the class is not a generic class, when used can not be added to the generic type - //properties<string, string> prop = new properties<string, string> (); - -Properties prop =NewProperties (); + - //adding elements +Prop.put ("it002", "Hello"); AProp.put ("it001", "World"); atProp.put ("it003", "Java"); - - //System.out.println ("prop:" + prop); - - //iterating through the collection -Set<object> set =Prop.keyset (); in for(Object key:set) { -Object value =Prop.get (key); toSYSTEM.OUT.PRINTLN (key + "---" +value); + } - } the}
Run the effect as follows:
Overview and use of the Java Fundamentals enhanced IO stream Note 66:properties (used as a map collection)