HashTable

HashTable的基本介绍

1)存放的元素是键值对,k-v

2)hashtable的键和值都不能为null,否则会抛出NullPointerException

3)hashTable使用方法基本上和HashMap一样

4)hashTable是线程安全的(synchronized),hashMap是线程不安全的

Hashtable hashtable = new Hashtable();
hashtable.put("01","成都");
hashtable.put("02","重庆");
//hashtable.put(null,"昆明");//空指针异常
//hashtable.put("03",null);//空指针异常
hashtable.put("04","广州");
hashtable.put("04","上海");//替换04
System.out.println("hashtable : " + hashtable );// 02=重庆 01=成都 04=上海

Properties

1.Properties类继承自HashTable类并且实现了Map接口,也是使用一种键值对的形式来保存数据

2.使用特点和Hashtable类似

3.Properties还可以用于从 xxx.properties文件中,加载数据到Properties类对象,并进行读取和修改

4.说明:工作后 xxx.properties 文件通常作为配置文件,

Java 读写Properties配置文件 - 旭东的博客 - 博客园

Properties properties = new Properties();
properties.put("01","成都");
properties.put("02","重庆");
//properties.put(null,"昆明");//空指针异常
//properties.put("03",null);//空指针异常
properties.put("04","广州");
properties.put("04","上海");//替换04
System.out.println("hashtable : " + properties );// 02=重庆 01=成都 04=上海
​
//删
properties.remove("04");
System.out.println("hashtable : " + properties );// 02=重庆 01=成都
//增
properties.put("05","南京");
System.out.println("hashtable : " + properties );// 02=重庆 01=成都 05=南京
//改
properties.put("05","北京");
System.out.println("hashtable : " + properties );// 02=重庆 01=成都 05=北京
//查
System.out.println(properties.get("05"));//  05=北京
System.out.println(properties.getProperty("05"));//   05=北京
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

jhan&

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值