Skip to content

Instantly share code, notes, and snippets.

@rayjcwu
Created March 20, 2014 22:40
Show Gist options
  • Select an option

  • Save rayjcwu/9675576 to your computer and use it in GitHub Desktop.

Select an option

Save rayjcwu/9675576 to your computer and use it in GitHub Desktop.
public String uniqueChar(String str) {
Set<Character> showed = new HashSet<Character>();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < str.length(); ++i) {
final char c = str.charAt(i);
if (!showed.contains(c)) {
showed.add(c);
sb.append(c);
}
}
return sb.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment