LinkedHashMap<Character,Integer> map = new LinkedHashMap<>(); public void Insert(char ch) { if(map.containsKey(ch)) { map.put(ch,-1); } else { map.put(ch, 1); } } public char FirstAppearingOnce() { Iterator<Character> iterator = map.keySet().iterator(); while (iterator.hasNext()) { char cur = iterator.next(); if(map.get(cur) == 1) { return cur; } } return '#'; }