I'm not sure if this is what you need, but here is your code I changed:
Map<String, String[]> map = new HashMap<String, String[]>(); map.put("key1", new String[]{"value1", "test1"}); map.put("key2", new String[]{"value2"}); Object[] keys = map.keySet().toArray(); Object[] values = map.values().toArray(); System.out.println("key = " + keys[0] + ", value #1 = " + ((Object[])values[0])[0]); System.out.println("key = " + keys[1] + ", value #1 = " + ((Object[])values[1])[0] + ", value #2 = " + ((Object[])values[1])[1]);
Output:
key = key2, value
Note that in the key[0] section, instead of "key1" is "key2" . This is because HashMap does not save the keys in the same order that you add them. To change this, you must choose a different Map implementation (e.g. TreeMap if you want to have an alphabetical order).
How it works? Java allows you to create arrays up to Object . toArray() returns an Object[] - an array of Objects , but these objects are also arrays (from String - as you defined on your map)! If you print only value[0] , it will be like printing mySampleArray , where mySampleArray :
Object[] mySampleArray = new Object[5];
So you call it not an element on the whole array. That is why you get [Ljava.lang.String;@7c6768 etc. (Which is the className @HashCode - this is what the default toString() method does).
To get to your element, you must go deeper.
((Object[])values[0])[0]
This means: take the values ββ[0] (we know that it contains an array), attribute it to the array and take the first element.
Hope this helps, let me know if you need more information.
byyyk source share