Just a guess, but centers
has 1000 elements, and you only set 5 of them. Maybe the other 995 are null
, giving you a HashSet with one more element than you expect (null
).
You can easily test this by printing the contents though:
for (String s : uniqueCenters) {
System.out.println("Got element: " + s);
}