I have a class with two methods load() and getValue(). The load function loads a set of key value pairs from a file onto a hashMap and the getValue(Object key) method is used to extract values for keys passed to it.
My problem is that I want to create an Object of the class such that load() should be executed only once (to load values into memory) and thereafter the getValue() method should be able to work on this data, each time its called.
What is the best approach to solve this problem? I am quite new to Java and OOP, so please feel free to modify either the question or the title to make it more clear.
You can use a static initializer block for your class. This is executed only once for a class.
http://www.glenmccl.com/tip_003.htm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With