So Basically I am generating random 10000 ip address and I wanted to store all those ip address that are found in HashSet but according to my calculation around 6000 ip address were found but in HashSet only 700 ip address are getting stored? Is there any limitations in HashSet in terms of storing String. Any suggestions will be appreciated.
Set<String> ipFine = new HashSet<String>();
long runs = 10000;
while(runs > 0) {
String ipAddress = generateIPAddress();
resp = SomeClass.getLocationByIp(ipAddress);
if(resp.getLocation() != null) {
ipFine.add(ipAddress);
}
runs--;
}
As far as you’re concerned, there is no limit (the limit is the max size of an array, which is 2**31).
However,
Setsonly store unique values, so my guess is that you only generated 700 unique addresses.Modify your code as follows:
This modification will mean you’ll keep looping until you get 10000 unique values.