一、基本介绍
1、Properties 类继承自 Hashtable类并且实现了Map接口,也是使用一种键值对的形式来保存数据
2、它的使用特点和 Hashtable 类似
3、Properties 还可以用于 从 xxx.properties 文件中,加载数据到 Properties 类对象,并进行读取
和修改
4、xxx.properties 文件通常作为配置文件
二、常用方法
1、put:增加、修改
2、remove:删除
3、get:查
import java.util.Properties;
public class Properties01 {
public static void main(String[] args) {
//1. Properties 继承 Hashtable
//2. 可以通过 k-v 存放数据,key 和 value 不能为 null
Properties properties = new Properties();
//properties.put(null, 20);//异常
//properties.put(20, null);//异常
properties.put("张三", 20);//ok
properties.put("李四", 30);//ok
properties.put("老六", 50);//ok
properties.put("老六", 100);//替换
System.out.println(properties);
//通过k 获取对应值
System.out.println(properties.get("张三"));
//删除
properties.remove("老六");
System.out.println(properties);
//修改
properties.put("张三", 999);
System.out.println(properties);
}
}