Solution Steps:
- Obtain char array from the input String
- Loop through the char array and add each char to a Set<Character>
package com.java.programs;
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()) {
characters.add(c);
}
return characters;
}
public static void main(String[] args) {
System.out.println(uniqueCharacters("aeroplane"));
}
}
[a, e, l, n, o, p, r]