1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
private static void getSingleN(String nums) { char[] chars = nums.toCharArray();
HashMap<Object, Integer> map = new HashMap<>(); for (char aChar : chars) { if (map.containsKey(aChar)) { Integer integer = map.get(aChar); integer++; map.put(aChar, integer); }else { map.put(aChar, 1); } } System.out.println(map);
for (Map.Entry<Object, Integer> entry : map.entrySet()) { if (entry.getValue()==1) { System.out.println("只出现一次的字符有:"+entry.getKey()); } }
}
|