Java - Stuck using HashMap, please help :)?
-
I'm new to HashMaps, and I hae read up on them and looked at videos online but i'm still stuck so any comments would be greatly appreciated :) private HashMap<LibraryItem, LibraryUser> myMap; (First of all, i'm not sure if this is correct. I want to store LibraryItems & LibraryUsers in this hashMap) HashMap myMap = new HashMap<LibraryItem, LibraryUser>(); (Constructor to create the new hashMap) public void storeLibraryItem(LibraryItem LibraryUser) { myMap.put(LibraryItem LibraryUser); } (I want to store LibraryItems & LibraryUsers in by using this code, but I know it is not right. Would I have 2 separate methods each adding, LibraryItems and the other LibraryUsers? Or does this work by adding whichever one it is to the hashMap?) Thanks for any comments, if you need more info just ask ! :D
-
Answer:
Do it like this : Map<LibraryItem,LibraryUser> myMap = new HashMap<LibraryItem,LibraryUser>(); public void storeLibraryItem(LibraryItem i, LibraryUser u) { myMap.put(i, u); } You almost had it.
Aahmed at Yahoo! Answers Visit the source
Related Q & A:
- Why cant i view my contacts display image? please help if you know ,thanks?Best solution by Yahoo! Answers
- I did something really bad and now i need help please help me.Best solution by Yahoo! Answers
- Help with TV show, please help?Best solution by Yahoo! Answers
- 10 Points!! Can You Please Help?Best solution by Yahoo! Answers
- Have any fundraising ideas? please help?
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.