public static void main(String[] args) { Map<String,Object> map = new HashMap<>(); map.put("1","A"); map.put("2","A"); map.put("3","F"); map.put("4","G"); map.put("5","H"); map.put("6","H"); map.put("7","G"); map.put("8","D"); map.put("9","F"); map.put("10","S"); map.put("11","S"); map.put("12","T"); map.put("13","Y"); map.put("14","O"); Map<String,Object> map2 = new HashMap<>(); List<String> list = new ArrayList<>(); for(Map.Entry<String,Object> entrySet : map.entrySet()) { if(!list.contains(entrySet.getValue())) { list.add((String) entrySet.getValue()); map2.put(entrySet.getKey(),entrySet.getValue()); } } System.out.println(list); System.out.println(map2); }
本文来自博客园,作者:狂躁的键盘,转载请注明原文链接:https://www.cnblogs.com/wangweiip/p/16412601.html