-1

Sorry a newb here

String [][] myExampleArray = {{"string1", ..., "string100"},{"string1", ..., "string100"}};

I want to put them in hashmap and my code looks like this

Hashmap <String[], String[]> mappedArrays = new Hashmap<>();
mappedArrays.put(myExampleArray[0], myExampleArray[1]);

I tried doing this:

for (var mappedArray : mappedArrays.entrySet())
  System.out.println(mappedArray.getKey() + " ==== " + mappedArray.getValue());

and it only shows one result:

[Ljava.lang.String;@372f7a8d ==== [Ljava.lang.String;@8efb846

how would I print all mappedArrays in key/value pair? Thank you so much guys!

jps
  • 20,041
  • 15
  • 75
  • 79
Mackyboy
  • 1
  • 1

1 Answers1

0

Your keys and values are arrays of strings, not strings. If you want to "stringify" your arrays, you can use Arrays.toString, like so:

for (var mappedArray : mappedArrays.entrySet())
  System.out.println(Arrays.toString(mappedArray.getKey()) + " ==== " + Arrays.toString(mappedArray.getValue()));

If you wanted the ith string in myExampleArray[0] to be mapped to the ith string in myExampleArray[1] instead, your HashMap will need to be of type HashMap<String, String>, and you'll need to loop over the arrays to put each (String, String) pair in.

Derek Lee
  • 46
  • 4