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.
Java

Avatar of undefined
Last Comment
gudii9

8/22/2022 - Mon
for_yan

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
gudii9

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy