public static void firstNoRepeatingChar(String str) { char[] strArr = str.toCharArray(); Mapmapc = new HashMap (); for (char c : strArr) { if (mapc.get(c) == null) { mapc.put(c, 1); } else { mapc.put(c, mapc.get(c) + 1); } } Set sc = mapc.keySet(); for (char c : sc) { if (mapc.get(c) == 1) { System.out.println(c); break; } } int[] strArr1 = new int[256]; for(char c : strArr){ strArr1[c]++; } for(int i = 0; i < 256; i++){ if(strArr1[i] == 1){ System.out.println((char)i); break; } } }