I am trying to have a user enter a String to search for a value in a list. This works fine, but I also want the String to have a numeric value. This way I can get the certain item in the lists price. I tried:
public List<String, double>
However this always gives me an error. How can I store strings and their corresponding numeric value?
Are you only storing a
Stringand aDouble, or will you eventually need to store more information about each object?For example, you’re talking about storing a name and a price. If this is for a shopping-like program, you would probably be best to store all the information for each product in a new class, and then store the class in the
HashMap. For example..You will then be able to query the
HashMapfor"Cheese"and you’ll get theProductand and all the information for it…