回首忆惘然
import java.util.ArrayList; import java.util.List; public class Test { public static void main(String[] args) { List<String[]> resultList = new ArrayList<String[]>(); List<String[]> list = new ArrayList<String[]>(); String[][] str = { { "阿迪达斯", "运动鞋", "2" }, { "阿迪达斯", "运动服", "3" }, { "阿迪达斯", "跑鞋", "4" }, { "耐克", "包", "5" }, { "耐克", "运动裤", "6" }, { "锐步", "包", "1" }, { "锐步", "运动裤", "6" } }; for (int i = 0; i < str.length; i++) { list.add(str[i]); } int count = Integer.parseInt(list.get(0)[2]); resultList.add(list.get(0)); for (int i = 0; i < list.size() - 1; i++) { if (list.get(i)[0] == list.get(i + 1)[0]) { count += Integer.parseInt(list.get(i + 1)[2]); resultList.add(list.get(i + 1)); } else { String[] temp = new String[3]; temp[0] = "合计"; temp[1] = ""; temp[2] = String.valueOf(count); resultList.add(temp); resultList.add(list.get(i + 1)); count = Integer.parseInt(list.get(i + 1)[2]); } } String[] temp = new String[3]; temp[0] = "合计"; temp[1] = ""; temp[2] = String.valueOf(count); resultList.add(temp); } } 仅供参考