list、set、map基础更新

一、ArrayList和HashSet的contains方法效率比较

结论放前面:HaseSet contains效率高

list
查询10000个对象 
共耗费时间:29694毫秒

set
查询10000个对象 
共耗费时间:975毫秒

测试代码

private void dowork() {
		
		List<String> list = new ArrayList<String>();
        Set<String> set = new HashSet<String>();
        
        for(int i = 0; i <= 100000; i++){
            list.add("haha"+i);
            set.add("haha"+i);
        }	
        
        long start = System.currentTimeMillis();
        for(int i = 0; i<= 100000; i++){
//            System.out.println(i+"__"+list.contains("haha"+i));
        System.out.println(i+"__"+set.contains("haha"+i));
        }
        
        long end = System.currentTimeMillis();
        System.out.println("查询10000个对象 \n共耗费时间:"+(end-start)+ "毫秒");
	}

二:ConcurrentHashMap线程安全

Map<String, String> conMap = new ConcurrentHashMap<String, String>();
Map<String, String> map = new HashMap<String, String>();
conMap.get(null);//会报错
map.get(null);//不报错

在这里插入图片描述
在这里插入图片描述
线程安全的List

List<String> dataList = Collections.synchronizedList(new LinkedList<String>());

线程安全的Int

AtomicInteger count = new AtomicInteger(0);
count.incrementAndGet();//+1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值