Link to home
Start Free TrialLog in
Avatar of dpalyca755
dpalyca755

asked on

static maps

How do I implement a static map class to be used by a few other classes?
examples to follow will be great.
Avatar of for_yan
for_yan
Flag of United States of America image

can you please elaborate?

HashMap as any Java object can be made static and then you could address it by refereinng to the class name rather than the instance of the class where it is a field
So if you declare it like that:
class ClassName {
public static HashMap<Integer, String> map;
...


}

Thane in any other class of your applucation you can address it like that:

ClassName.map.get(key)

thsi is no different form any other static object
ASKER CERTIFIED SOLUTION
Avatar of gudii9
gudii9
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial