显示串中只出现一次的字符.

public static void firstNoRepeatingChar(String str) {
		char[] strArr = str.toCharArray();
		Map<Character, Integer> mapc = new HashMap<Character, Integer>();
		for (char c : strArr) {
			if (mapc.get(c) == null) {
				mapc.put(c, 1);
			} else {
				mapc.put(c, mapc.get(c) + 1);
			}
		}

		Set<Character> 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;
			}
		}
	}



你可能感兴趣的:(显示串中只出现一次的字符.)