代码改变世界

输出只出现一次的字符

2016-02-26 16:48  一切尽在掌握  阅读(201)  评论(0编辑  收藏  举报
	/**
	 * 输出只出现一次的字符
	 */
	private void testB() {
		String str = "abfab";
		HashMap<Character, Boolean> map = new HashMap<Character, Boolean>();
		for (int i = 0; i < str.length(); i++) {
			char a = str.charAt(i);
			if (map.containsKey(a)) {
				map.put(a, false);
			} else {
				map.put(a, true);
			}
		}
		Iterator<Character> it = map.keySet().iterator();
		while (it.hasNext()) {
			char c = it.next();
			if (map.get(c).booleanValue()) {
				Logger.i("test", "字符 == " + c);
			}
		}
	}