HashMap和Hashtable

package com.cavaness.quartzbook.chapter3;

import java.util.HashMap;
import java.util.Hashtable;

public class Test {
	public static void main(String[] args) {
		String string = null;
		HashMap<String, Integer> hash = new HashMap<String, Integer>();
		hash.put("", 1);
		hash.put(string, 2); // 编译和运行都成长
		
		Hashtable<String, Integer> hashtable = new Hashtable<String, Integer>();
		hashtable.put("", 1);
		hashtable.put(string, 2); // 编译通过,运行异常
		/*
		  就HashMap与HashTable主要从三方面来说。 
		一.历史原因:Hashtable是基于陈旧的Dictionary类的,HashMap是Java 1.2引进的Map接口的一个实现 
		二.同步性:Hashtable是线程安全的,也就是说是同步的,而HashMap是线程序不安全的,不是同步的 
		三.值:只有HashMap可以让你将空值作为一个表的条目的key或value,HashTable不允许 
		 */
	}
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值