If you really need Set<String[]> , thereβs no easy and elegant way to do this, AFAICT. The problem is that arrays do not override equals() and hashCode() , on the one hand. On the other hand, the HashSet class does not provide the ability to pass some βstrategyβ for it, which will implement a hash code and equality computation from the outside (something like Comparator ). Therefore, you can create a TreeSet using a special comparator. Unfortunately, I do not know any implementation of an array comparator, so most likely you will need to write your own.
If you are comfortable having Set<List<String>> , you can consider the advice in other answers.
Alexey
source share