感谢米聊java群的小伙伴的指导,特此记录
创建并使用二维List
List<List<String>> str = new LinkedList<>(); //外层的
List<String> stringList = new LinkedList<>();//内层的
str.add(stringList);//内外关联
str.get(0).add("测试数据");//可以进行操作了
把List address一维集合变为二维
List<List<String>> multiArray = new LinkedList<>(); //外层的
List<String> areaList = new LinkedList<>();//内层的
multiArray.add(areaList);//内外关联
for(Address addressIndex:addressList){
if(!areaList.contains(addressIndex.getArea())) {
areaList.add(addressIndex.getArea());
multiArray.add(new LinkedList<>());
}
//-----
Integer index = areaList.indexOf(addressIndex.getArea());
multiArray.get(index+1).add(addressIndex.getLocation());
}