java查找大数组中的值

简介

一个csv文本有3行,10w列,我读入第一行,用‘,’拆分,把10w列放到array中。
我有一个str,我需要知道这个str在第一行的下标,从而在第23行直接用下标获得对应的值。
由此引发对数据效率的思考。

1.最笨的方法

for循环慢慢比较

public void jxCsv(File file ){
        BufferedReader br = new BufferedReader(new FileReader(file));
        String line = "";
        String[] arrayLine = null;
        int index = -1;
        int time = 0;
        while((line=br.readLine())!=null){
            if(time==0){
                arrayLine = line.split(",");
                for(int i=0;i<arrayLine.length;i++){
                    if(arrayLine[i].equals(countNum)){
                        index = i;
                    }
                }
            }
            输出每一行的信息
        }
    }

2.使用hashMap,将array的数据放到map中,数组的值作为map的键,数组的下标作为map的value

以前听过hashMap查找速度最快,由键确定值也只有map了,但是,放到map中也要花费时间啊。

3.开多线程,每个线程遍历数组的1w个,使用callable

猜你喜欢

转载自blog.csdn.net/qq_29778641/article/details/81737144