Overview and use of the Java Fundamentals enhanced IO stream Note 66:properties (used as a map collection)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.