I'm trying to use Hashmap in Java 8. I will use the hash function to get the index to put the node with given key and value. However, if there are nodes with the same key, I have to use Linked List kind of data structure. This is where I'm confused about.
For example, if there are
package First;
import java.util.HashMap;
public class MyClass extends Node {
public MyClass(int k, int v) {
super(k, v);
// TODO Auto-generated constructor stub
}
public static void main(String[] args) {
HashMap<String, Node> capitalCities = new HashMap<String, Node>();
capitalCities.put("England", new Node(1,3));
capitalCities.put("Germany", new Node(1,3));
capitalCities.put("Norway", new Node(1,3));
capitalCities.put("USA", new Node(1,3));
capitalCities.put("USA", new Node(1,3));
System.out.println(capitalCities);
}
}
If I print h1, it will only have "APPLE", 13 So I want to make the Hashmap to be like this: "APPLE", 1 -> "APPLE", 10 -> "APPLE", 13