Map接口的实现Properties
基本介绍
- properties类继承了hashtable类,并且实现了map接口,也是使用一种键值对的形式来保存数据
- 使用特点与hashtable类似
- properties还可用于从 xxx.properties文件中,加载数据到properties类对象
- properties通常作为配置文件
基本使用
package com.lyc._Map._HashTable;
import java.util.Properties;
public class properties01 {
public static void main(String[] args) {
Properties properties = new Properties();
properties.put(1,"水浒");
properties.put(2,"三国");
properties.put(3,"红楼");
properties.put(4,"西游");
properties.put(4,"聊斋");//如果有相同的key,则values值会被替换
//因为properties是hashtable的子类,所以也不允许出现null值
//properties.put(null,"11");
//properties.put(6,null);
System.out.println(properties);
//通过key获取value值,查找
System.out.println(properties.get(1));
//通过key删除元素
properties.remove(2);
System.out.println(properties);
//修改元素,也就是覆盖
properties.put(3,"三国");
System.out.println(properties);
}
}