Java学习笔记 --- Properties

一、基本介绍

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);
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值