![]() |
HashTable class
Hi.. I'm writing this HashTable class and I'm not sure what this error is from. I get it when I run this short little test program with more than two calls to put. Any help would be greatly appreciated. Note: The Pair<K,V> class is just basically a K key and V value with getKey and getVal methods.
The Error Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 2, Size: 2 at java.util.ArrayList.RangeCheck(Unknown Source) at java.util.ArrayList.get(Unknown Source) at HashTable.put(HashTable.java:77) at HashTest.main(HashTest.java:9) The Test Program That Produces The Error :
The HashTable class :
|
Re: HashTable class
Start your debugging quest by realizing that indices in Java are based on a half-open range. In an array of size N, the valid indices are 0 to N - 1.
|
Re: HashTable class
Look at <, <=
|
Re: HashTable class
<= would mean that local variable i would be equal to or less then, which is not what you're aiming for.
What you're aiming for is actually: :
Oh, and Object.equals(Object) return Object == Object, but equals(Object) is overridden in special cases so there is no need for pair.getKey() == key. |
| All times are GMT -5. The time now is 3:24 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC