Two Laptop Bag
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

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: 24189

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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: HashMap code repetition
jQuery in Action, 3rd edition