栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Map接口的实现Properties

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Map接口的实现Properties

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


    }
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/631524.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号