Find Unique Characters in the String

Solution Steps:

  1. Obtain char array from the input String
  2. Loop through the char array and add each char to a Set<Character>
import java.util.Set;
import java.util.TreeSet;
public class UniqueCharacters {
	public static Set<Character> uniqueCharacters(String input){
		Set<Character> characters = new TreeSet<>();
		for(char c: input.toCharArray()) {
		return characters;
	public static void main(String[] args) {
 [a, e, l, n, o, p, r]

Leave a Reply

Your email address will not be published. Required fields are marked *