Map存储的是引用地址
场景
在做一个短信的发送分组,超过100000个号码需要对号码文件进行拆分,思考了一下,觉得可以遍历一次文件,利用Map<Integer, List>存储号码,key为分组标记值,value为号码列表。
问题
在创建List时,放在了while的外面,相当于只创建了一次对象
BufferedReader reader = getBufferedReader(filePath);
List<String> mobileList = new ArrayList<>();
String line;
Long lineIndex = 0L;
int mapIndex = 1;
while ((line = reader.readLine()) != null){
String mobile = line.trim();
if (line.equals("")) {
continue;
}
if (mobile.startsWith(Constants.COUNTRY_CODE) == true) {
// 清除86前缀
mobile = mobile.substring(2);
}
mobileList.