-2

Consider I have a HashMap like the below example:

private static Map<String, Double, Integer, Integer> Items = new HashMap<>();
    // item name Price CurrentStock, Minimum Stock
    Items.put("Chocolate", 1.35, 13, 11 );

How would I make it check if the 13 is the 11 or below~? Is this possible with HashMaps, if not what should I do?

Avi
  • 21,182
  • 26
  • 82
  • 121
Adam200214
  • 17
  • 3
  • oops.... this program won't even compile. you need to study some basic tutorial about what is map and how to use it. what is map? – Pranalee Jan 25 '16 at 12:54
  • You cannot have a Map like that. Map has key value pairs. You can have HashMap or HashMap. Please learn about collections before trying to use them – P. Jairaj Jan 25 '16 at 12:57
  • Sorry, I quickly wrote it up and kind off in a hurry, forget the item name Just use ::: private static Map Test = new HashMap<>(); Test.put(13, 11); How would I check if that 13 is below that 11 if so do something – Adam200214 Jan 25 '16 at 12:58
  • Also sorry, I'm relatively new to Java and trying to learn how to use HashMaps for a personal project – Adam200214 Jan 25 '16 at 12:59

1 Answers1

1

Maps have only a key and a value. You can use Map<KeyType,List<ValueType>>

For example

Map<String,List<Integer>> map = new HashMap<String,List<Integer>>();
List<Integer> list = new ArrayList<Integer>();
list.Add(1.35);
list.Add(13);
list.Add(11);
map.Add("Chocolate",list);

And then check

List<Integer> chocolate = map.get("Chocolate");    
if (chocolate.get(1) < chocolate.get(2)) {
    //do something
}
TEuler27
  • 220
  • 1
  • 9