In my code I am trying to get if a number exist in the hashmap or not. My code is following:
BitSet arp = new BitSet();
for i = 0 to 10 million
HashMap.get (i)
if number exist
arp.set(i , true)
else
arp.set(i , false)
After that from bitset I get if number i exist or not. However, I found this bitset operation is quite slow (tried with string = string + 0/1 also, more slower). Can anybody help me how to replace this operation with a faster one.
Your code is really difficult to read clearly, but I suspect you’re just trying to set bits in the
BitSetthat are keys from yourHashMap?In that case, your code should just be more or less
Even if this wasn’t what you meant, as a general rule,
BitSetis blazing fast; I suspect it’s the rest of your code that’s slow.