Search

Dark theme | Light theme

April 27, 2011

Groovy Goodness: Get Unique Characters in a String

Groovy adds the toSet() method to the String class in version 1.8. With this method we get a Set of unique String values from the original String value.

String s = 'Groovy is gr8!'

assert s.toSet().sort().join() == ' !8Ggiorsvy'