Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.HashMap; import java.util.List; public class Main { public static HashMap<String, List<Object[]>> getUnitDataMapList(List<Object[]> list, int[] indexnum) { HashMap<String, List<Object[]>> dataMap = new HashMap<String, List<Object[]>>(); for (int i = 0; i < list.size(); i++) { StringBuffer returnStringBuffer = new StringBuffer(); for (int ai = 0; ai < indexnum.length; ai++) { int index = indexnum[ai]; Object obj = list.get(i)[index]; String gunit = obj.toString(); if (ai == 0) { returnStringBuffer.append(gunit); } else { returnStringBuffer.append("(" + gunit + ")"); } } String unit = returnStringBuffer.toString(); if (dataMap.containsKey(unit)) { dataMap.get(unit).add((Object[]) list.get(i)); } else { ArrayList<Object[]> rowdata = new ArrayList<Object[]>(); rowdata.add((Object[]) list.get(i)); dataMap.put(unit, rowdata); } } return dataMap; } }