Reputation: 183
I am trying to add the key values from a Treemap to a String[], but i am doing something wrong and i get this: "[Ljava.lang.String;@281ec58a". Can anyone help? Thanks in advance.
This is the code i'm using:
TreeMap t = new TreeMap(hm); //hm is a Hashmap
t = (TreeMap) sortByValues(t); // i sort the values with this method
String [] tempa = (String[]) t.keySet().toArray(new String[t.size()]);
Upvotes: 0
Views: 5684
Reputation: 1500185
It's entirely unclear what the values within the HashMap
and TreeMap
are, because you're using the raw types. Your code would be clearer to us, you and the compiler if you used generics.
However, it could well be that everything is fine - it's just that you're converting the string array to a string somewhere by calling toString
on it. (You haven't told us what you mean by "i get this" - where?)
Try using:
String output = Arrays.toString(tempa);
to see what the values within the array are.
Upvotes: 2
Reputation: 500267
"[Ljava.lang.String;@281ec58a"
is simply how arrays are printed (i.e. converted to a string) by default. If you iterate over the contents of the array, and print each element in turn, you'll likely find that everything is as expected.
Upvotes: 2