Sorting colors by the name of the color I was in need to sort Colors, so the first thing that I tried was this:

Arrays.sort(new javafx.scene.paint.Color[] {Color.ALICEBLUE},Color.AZURE,Color.BLUEVIOLET,Color.AQUA,...);


But unfortunately Arrays.Sort is not compatible with javafx.scene.paint.Color, so I ended up with this:

public static void main(String[] args) {
    final String[] colors = {"AQUA", "LAWNGREEN", "LIGHTBLUE", "CYAN", "CHOCOLATE", "GREEN",
        "RED", "YELLOW", "GAINSBORO", "YELLOWGREEN"};

    final Function&lt;String, ? extends Color&gt; valueMapper = (final String name) -&gt; {
        try {
            return (Color) Color.class.getField(name).get(null);
        } catch (final IllegalAccessException | IllegalArgumentException | NoSuchFieldException | SecurityException e) {
            throw new RuntimeException(e);
        }
    };
    final Map&lt;String, Color&gt; map = Arrays.stream(colors).collect(
            Collectors.toMap(Function.identity(), valueMapper));

    map.entrySet().stream().sorted(Comparator.comparing(Entry::getKey)).forEach((Entry&lt;String, Color&gt; entry) -&gt; {
        System.out.println(entry.getKey() + " = " + entry.getValue());
    });

}


Now let me know if this code can be improved and optimized.
I like your approach with mapping function, but sorting alphabetically the collection of javafx.scene.paint.Color objects can be done a little bit easier:

    final String[] colors = {"AQUA", "LAWNGREEN", "LIGHTBLUE", "CYAN", "CHOCOLATE", "GREEN",
            "RED", "YELLOW", "GAINSBORO", "YELLOWGREEN"};

    Stream.of(colors).sorted().map(color -&gt; Color.web(color)).forEach(System.out::println);


as you can see the algorithm quite simple:


Sort the string array
Map string to Color object using API method