I am trying to use a hashset to count the amount of strings in a string array without counting duplicates. However, this program is not working correctly. For eg. this code prints out "4", when in truth their are only 3 unique strings. Does anyone know why this is working incorrectly?
String centers[]=new String[1000];
/* Only for Testing Purposes*/
centers[0] = "Soccer";
centers[1] = "Soccer";
centers[2]= "Baseball";
centers[3] = "Table Tennis";
centers[4] = "Soccer";
List<String> centerList = Arrays.asList(centers);
Set<String> uniqueCenters = new HashSet<String>();
uniqueCenters.addAll(centerList);
Integer numberOfUniqueStrings = uniqueCenters.size();
System.out.println(numberOfUniqueStrings);