public class TestHashSetAndHashMap {

private final int setNum=5000;

@Test
public void doTest(){

List<Set<Long>> testList=new ArrayList<Set<Long>>();
for(int i=0;i<setNum;i++){
Set<Long> testSet =new HashSet<Long>();
for(int j=0;j<setNum;j++){
testSet.add((long) (i+j));
}
testList.add(testSet);
}

HashMap<Long,Long> map=new HashMap<Long,Long>();

{
long start=System.currentTimeMillis();
for(Set<Long> each:testList){
for(Long id:each){
map.put(id,id);
}
}

System.out.println("cost1="+(System.currentTimeMillis()-start));
System.out.println("map="+map.size());
}

{
Set<Long> allSet=new HashSet<Long>();
long start=System.currentTimeMillis();

for(Set<Long> each:testList){

allSet.addAll(each);
}

System.out.println("cost2="+(System.currentTimeMillis()-start));
System.out.println("allSet="+allSet.size());
}

}

}

结果是

cost1=1216
map=9999
cost2=1136
allSet=9999

HashSet和HapMap取distinct value的更多相关文章

  1. 取distinct数据同时还取其他字段

    的 SELECT id,group_concat(distinct model) FROM tsdr_case group by model order by id

  2. mssql sqlserver text、image字段类型无法使用DISTINCT的处理方法分享

    转自: http://www.maomao365.com/?p=9775  摘要: 下文简述sqlserver数据库中 text image类型无法使用distinct的处理方法分享 实验环境:sql ...

  3. Java集合【2】--iterator接口详解

    目录 一.iterator接口介绍 二.为什么需要iterator接口 三.iterator接口相关接口 3.1 ListIterator 3.2 SpitIterator 3.2.1 SpitIte ...

  4. SORT UNIQUE|AGGREGATE|GROUP BY|ORDER BY|JOIN

    相信做oracle开发和管理的朋友对sort肯定不会陌生,大家通常都遇到这样那样的排序性能问题,所以我写这一系列关于sort的文章告诉大家在oracle里面sort是怎么一回事以及如果调整sort获得 ...

  5. Matlab 图像的邻域和块操作

    图像的邻域操作是指输出图像的像素点取值,由输入图像的某个像素点及其邻域内的像素,通常像素点的邻域是一个远小于图像本身尺寸.形状规则的像素块,如2×2,3×3正方形.2×3矩形等,或者近似圆形的多边形. ...

  6. Oracle 行转列 动态出转换的列

    本文链接:https://blog.csdn.net/Huay_Li/article/details/82924443 10月的第二天,前天写了个Oracle中行转列的pivot的基本使用方法,然后, ...

  7. 面试话痨(二)C:JAVA String,别以为你穿个马甲我就不认识你了

    面试话痨系列是从技术广度的角度去回答面试官提的问题,适合萌新观看!   面试官,别再问我火箭怎么造了,我知道螺丝的四种拧法,你想听吗? String相关的题目,是面试中经常考察的点,当面试中遇到了St ...

  8. SpringCloud 源码系列(6)—— 声明式服务调用 Feign

    SpringCloud 源码系列(1)-- 注册中心 Eureka(上) SpringCloud 源码系列(2)-- 注册中心 Eureka(中) SpringCloud 源码系列(3)-- 注册中心 ...

  9. 【Nodejs】理想论坛帖子爬虫1.01

    用Nodejs把Python实现过的理想论坛爬虫又实现了一遍,但是怎么判断所有回调函数都结束没有好办法,目前的spiderCount==spiderFinished判断法在多页情况下还是会提前中止. ...

随机推荐

  1. EF测试自动修改数据库结构

    1.配置类 <connectionStrings> <add name="test1" connectionString="Data Source=.; ...

  2. Button四角有弧度及按下显示不同的颜色

    一般的button都是矩形或者正方形,但为了显示不同的效果,让界面更美化,可以对其进行处理!!! 1.四角有弧度的button 2.按下button显示不同的颜色 实现步骤: 首先在drawable文 ...

  3. hihocoder SAM基础概念

    后缀自动机一·基本概念 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi:今天我们来学习一个强大的字符串处理工具:后缀自动机(Suffix Automaton,简称 ...

  4. 使用NSScanner,将十六进制字符串转十进制

    例子:  NSString * numStr = [@"0x110" substringFromIndex:2]; unsigned long long result = 0; N ...

  5. 浅谈rem、em、px

    1.px:像素(Pixel) px是相对长度单位,他是相对于显示器屏幕分辨率而言的 优点:比较稳定.精确 缺点:在浏览器 中放大或者缩小浏览页面,会出现页面混乱的情况. 如下例子: .buttonPX ...

  6. QT toLocal8Bit奇怪的问题

    #include "mainwindow.h" #include "ui_mainwindow.h" #include<QDebug> MainWi ...

  7. Javascript 处理时间大全

    1. 获取从今天算起,几天后的日期 function GetDateStr(AddDayCount) { var dd = new Date(); dd.setDate(dd.getDate() + ...

  8. call_user_function()方法的使用

    call_user_func ( callback $function [, mixed $parameter [, mixed $... ]] ) 调用第一个参数所提供的用户自定义的函数. 返回值: ...

  9. Fuzzy Probability Theory---(3)Discrete Random Variables

    We start with the fuzzy binomial. Then we discuss the fuzzy Poisson probability mass function. Fuzzy ...

  10. 遇到的sql关键字

    select count(1)  相当于  select count(*)  网上有比较差别的 菜鸟不用管