This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I think this means to write a class that works like Map but uses ArrayList internally. I was actually fool enough to do this with Vector my first week of Java because I hadn't thought to look in the API and find maps. What does a map have? Keys and values. How would you store a bunch of keys and a bunch of values to make these two methods work:
public Object get( key ) public void put( key, value )
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I guess you can. in ArrayList, index might be a key as in HashTable and using get(int index); will return the object
SCJP 1.4, SCWCD 1.4<br />email:firstname.lastname@example.org
Joined: Apr 05, 2006
Yeah you can use index in List as an Key in hashmap. But if they give any object, so we have to store that one also. Here i got an idea , when ever you are writting your own put method, you have to use two array lists, in which one takes key and another takes value objects. So, the index of the one key and value pair will be the same. In get method , you will get a key, by taking that keys list and by iterating you can get the index of that key and by using the same index you can get the object from the another list(because the indexes of the key and value are same). So you can return that value from your get method.
But instead of this logic there is something, means using one or two method we can implement the Hasmap by using the list. That i want,
you have to use two array lists, in which one takes key and another takes value objects
Yeah, that's what I did before I found the Map interface. Then ... well, we don't have a smack self on forehead smiley.
Of course we have to ask if the original question of implementing hashmap required using hashes. This two-list approach would be fine if he said replace HashMap or implement Map, but there's no hash in sight.