-3

In hashmap how to give Integers in below form repersentation.i tried but i can't get solution.

(1,2)=17;

user306128
  • 101
  • 4

2 Answers2

0

This is a multi-key hashmap. The basic idea is to create two hashmaps and chain them together. See this question for a duplicate answer.

Community
  • 1
  • 1
wyas
  • 377
  • 2
  • 14
  • How do you know the OP wants two keys to map to 17 as opposed to a [tuple](https://en.wikipedia.org/wiki/Tuple) containing `1,2`? – azurefrog Oct 06 '15 at 19:03
  • I didn't really think about the tuple, good point. But then it can just be treated as an atomic, immutable key, and go about it the usual way. – wyas Oct 06 '15 at 19:09
0

Step 1: Create a custom Tuple class. Use the code from accepted answer to this question => Using Pairs or 2-tuples in Java.

Thanks to @azurefrog for the tip.

Step 2: The type of the HashMap holding this would be

HashMap<Tuple, Integer> myMap = new HashMap<Tuple, Integer>();

Hope this helps :-)

Community
  • 1
  • 1
kkaosninja
  • 1,301
  • 11
  • 21