I need java equivalent for next python
In [1]: d = {} In [2]: k = ("x","2") In [3]: d[k] = 1 In [4]: print d[("x","y")] 1
Python has tuples that you can use. I tried unsuccessfully to follow in Java
Map<String[], Integer> d = new HashMap<String[], Integer >(); String[] k = new String[]{"x", "y"}; d.put(k, 1); System.out.println(d.get(k)); System.out.println(d.get(new String[]{"x", "y"}));
He outputs
1 null
This means that a reference to String [] receives a hash instead of a value.
An inefficient way that I can think of is to concatenate the elements from String [] into one string.
Is there a better way?
Thanks in advance!
source share