设置一个3000000长度的List,其中list里的内容为“hero-7777”的形式,即"hero-四位数",要求遍历整个list,给出该List里有多少个’‘hero-7777’’(返回数量及位置)
结果:
初始化List成功
HashMap耗时:0
共有多少个(hero-7777) 340
for循环耗时:62
共有多少个(hero-7777) 340
HashMap方法
Map的key为:’’‘hero-四位数字’,值为:该key在list中的位置
public static void Method1(List<String> testList) {
HashMap<String,List<Integer>> HeroMap = new HashMap<>(); //设置HashMap的形式,key为string类型,value为list类型(value也可以为对象)
for(int i = 0;i < testList.size();i++){
List<Integer> listHeroNum = HeroMap.get(testList.get(i).toString