Skip to content

Instantly share code, notes, and snippets.

@arose13
Created June 5, 2016 21:16
Show Gist options
  • Save arose13/0c71381a67897717b866c0b8c9f01eba to your computer and use it in GitHub Desktop.
Save arose13/0c71381a67897717b866c0b8c9f01eba to your computer and use it in GitHub Desktop.
Gets all the unique characters from a string in Java
// Find all unique characters in the string
String uniqueLettersInTestString = "";
for (int i = 0; i < testString.length(); i++) {
if (!uniqueLettersInTestString.contains(String.valueOf(testString.charAt(i)))) {
uniqueLettersInTestString = uniqueLettersInTestString + String.valueOf(testString.charAt(i));
}
}
System.out.println("Unique Letters are: " + uniqueLettersInTestString);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment