permaculture playing cards*
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
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: 24187
    
  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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: HashMap code repetition