Java tutorial
import java.util.Arrays; import java.util.Set; import java.util.TreeSet; public class Main { public static void main(String[] args) { String[] s = { "a", "y", "x", "a", "d", "y", "m", "a", "bc" }; System.out.println(Arrays.toString(s)); System.out.println(Arrays.toString(clean(s))); } public static String[] clean(String[] input) { Set<String> unique = new TreeSet<>(Arrays.asList(input)); return unique.toArray(new String[unique.size()]); } }