This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes HashMap code repetition Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "HashMap code repetition" Watch "HashMap code repetition" New topic
Author

HashMap code repetition

Ramakrishnan Viswanathan
Ranch Hand

Joined: Aug 24, 2005
Posts: 90
Hi

I have a HashMap with 10 entries. I have 2 classes that need to use this HashMap. Unfortunately these 2 classes are not related to each other in any way.

I have ended up with a situation where I have to repeat the code for creating and populating the HashMap in both the classes.

Is there any way I can avoid this code duplication?

Thanks in Advance
Ram


Regards<br />Ram<br /> <br />SCJP 1.4, SCBCD 1.3, (SCEA)
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Populate the HashMap in a class which is accessable by both.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Also, please see this document.


[Jess in Action][AskingGoodQuestions]
Ramakrishnan Viswanathan
Ranch Hand

Joined: Aug 24, 2005
Posts: 90
Thank you. I apologize for posting this in two places. I am really sorry about that.
 
jQuery in Action, 2nd edition
 
subject: HashMap code repetition
 
Similar Threads
Object is null
HOW TO CREATE HASH MAP USING ARRAYLIST??
Hashmap
Generics question
Difference in "? extends Object" and "Object" in Generics