today I tackled this coding challenge: Remove duplications from string.
I was thinking of either using a Hashmap or a Set but realized that a set might have a longer run time since the way it determines if a numbers is in there or not is by traversing each element. This lead me to use a hashmap instead. I have not taken care of any edge cases but wanted to get people's opinion of this implementation. From what I understand this would be a \$O(n)\$, (\$n\$ being the length of the input String), correct?
String test = "Banana";
HashMap<Character, String> nodups = new HashMap<>();
for(int i = 0; i < test.length();i++){
nodups.put(test.charAt(i),String.valueOf(test.charAt(i)));
}
StringBuilder noDupsString = new StringBuilder();
for(Character key : nodups.keySet()){
noDupsString.append(nodups.get(key));
}
System.out.println("String value with no dups :" + noDupsString);
}