首页 > 学院 > 开发设计 > 正文

IO流_Properties的概述和作为Map集合的使用

2019-11-06 07:53:11
字体:
来源:转载
供稿:网友
package cn.itcast_08;import java.util.Map.Entry;import java.util.PRoperties;import java.util.Set;/* * Properties:属性集合类。是一个可以和IO流相结合使用的集合类。 * Properties 可保存在流中或从流中加载。属性列表中每个键及其对应值都是一个字符串。 *  * 是Hashtable的子类,说明是一个Map集合。 */public class PropertiesDemo {	public static void main(String[] args) {		// 作为Map集合使用		// 下面这种做法是错误的,一定要看API,如果没有<>,就说明该类不是一个泛型类,在使用的时候就不能加泛型		// Properties<String,String> p = new Properties<String,String>();		Properties prop = new Properties();		// 添加元素		prop.put("itcast02", "hello");		prop.put("itcast01", "world");		prop.put("itcast03", "java");		// System.out.println("prop:" + prop);		// 遍历集合		// 丈夫找妻子		Set<Object> set = prop.keySet();		for (Object key : set) {			Object value = prop.get(key);			System.out.println(key + "---" + value);		}		// 结婚证找丈夫和妻子		// Set<Entry<Object, Object>> set = prop.entrySet();		// for (Entry<Object, Object> e : set) {		// System.out.println(e.getKey() + "---" + e.getValue());		// }	}}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表