For context, I'm doing some kind of game in Java where there are hundreds of items. And other than their unique name (which serves as id aswell) they also have a numeric price.
Where do I store all those hard-coded price values for each item? Do I make a constants class for all of them? And if so how would I search for the specific price of the item "shovel"? Since there are no dictionaries in Java like there are in Python for example. Or do I need to use a database even though they will probably never change?
Java does have "dictionaries", except it's called
java.util.Map(with implementations likeHashMaporTreeMap). There is alsojava.util.Properties, which is probably what I would use here in combination with a resource.The properties file itself (
my.properties) is then located in the same location as the class file. Its content is a list of key-value pairs: