As far the problem you may be facing from this code is that you cannot retrieve your values by whatever arguments you try, like if you enter args as "Charis" you cannot retrieve your object back , the reason being:-
1. HashMap uses hashCode() to match the key (Friends) in your case and equals to find the correct value , which is not overridden in your Friends class.
2. So when your are using get(new Friends(args)) , it is generating a new object with a random hashCode() generated by original hashCode() function of an Object Class and it returns null as it may not match the hashcode generated by original Charis Friends instance that was added in the map.
Override hashCode() and equals() ) in your Friends class to something unique number like name.length and equals to make them meaningfull equal and you can access it.
The Map retrieval works like this:-
1.Check if hashCode matches with any hashCode in map
2. If Yes, find the correct object with equals method.
Welcome again. Actually, not quoting the source of the question is not optional at JavaRanch. I see that they even have a policy on that.
Javaranch Policy wrote:When asking any question, please quote your sources. Quoting your sources means that you mention where you got the question from: for example the title and authors of a book, the name of a mock exam, address of a website where you got the question from etc.
This is especially important in the certification forum, for the posting of mock questions. This is needed for several reasons:
It is polite and professional to do so. Giving attribution is an important habit, and the author of the source would appreciate it.
For mocks, it will help people find the mock exam. For other cases, it will provide people with a source of information. In either case, it will help put your question in context.
It helps you if other people can check that you have interpreted the question (or the information) in the same way as the author intended.
Note: Do not post questions that you got on the actual exam. Those questions are copyrighted and you are not allowed to republish them.
Besides that, most books and such materials have copyrights associated with them. Mentioning the source of the question often helps with copyrights.
Also, attribution is always a nice thing.
So please take a moment to mention the source of your question. And welcome again.