package collection;
import character.Hero;
import java.util.*;
public class TestCollection {
public static void main(String[] args) {
List heros = new ArrayList<>();
for(int i =0;i<300*10000;i++){
heros.add(new Hero("hero-"+(int)(Math.random()*9000+1000)));
}
System.out.println(heros.get(0));
int index = 0;
int n = 0;
long start = System.currentTimeMillis();
for(Hero h:heros){
if("hero-5555".equals(h.name)){
System.out.println((index++)+" : "+h.name);
n++;
}
}
long end = System.currentTimeMillis();
System.out.println((end-start)+"毫秒");
HashMap> heroMap = new HashMap>();
for(Hero h:heros){
List list = heroMap.get(h.name);
if(null==list){
list = new ArrayList<>();
heroMap.put(h.name,list);
}
list.add(h);
}
long start1 = System.currentTimeMillis();
List result = heroMap.get("hero-5555");
long end1 = System.currentTimeMillis();
System.out.printf("一共找到%d个英雄,耗时:%d毫秒",result.size(),(end1-start1));
}
}