I'm getting this error in this line of code:
for (int i = Math.abs(key.hashCode()) % size; i < size; i++)
why is this happening?
The % operator returns the remainder after dividing the first number by the second number. If the second number (in your example size
) is zero, then you will get a divide by zero ArithmeticException
.
The key is to check if size
is zero before performing this loop, and take the appropriate action.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.