File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "HashMap code repetition" Watch "HashMap code repetition" New topic

HashMap code repetition

Ramakrishnan Viswanathan
Ranch Hand

Joined: Aug 24, 2005
Posts: 90

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

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

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

Joined: Jul 08, 2003
Posts: 24199

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.
I agree. Here's the link:
subject: HashMap code repetition
It's not a secret anymore!