一组字符串编程
public static void shiTi1() { List<String> list = Arrays.asList(new String[]{"1,张三,50","2,李四,80","3,王五,40","4,张三,90","5,王五,70"}); TreeMap<String, Integer> scott = new TreeMap<String, Integer>( /*new Comparator<String>(){ public int compare(String o1, String o2) { return o2.compareTo(o1); } }*/); TreeMap<Integer, String> last = new TreeMap<Integer, String>(); String found[] = new String[3]; for(int i = 0; i < list.size(); i++) { found = list.get(i).split(","); if(scott.get(found[1]) != null) { scott.put(found[1], (scott.get(found[1])+Integer.valueOf(found[2]))/2); } else { scott.put(found[1],Integer.valueOf(found[2])); } } for(Object m0: scott.entrySet()){ last.put(((Map.Entry<String, Integer>) m0).getValue(),((Map.Entry<String, Integer>) m0).getKey()); } for(Object m0: last.entrySet()){ System.out.println(((Map.Entry<Integer, String>) m0).getValue()+"---"+((Map.Entry<Integer, String>) m0).getKey()); } }