File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting array back from map

 
Jukka Kuusamo
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey

I'm wondering how to get array back that I placed in map as


When I try to print map.keySet() I get


It's kinda weird that when I try to StringTokenizer it then I get only object that object gibberish


I would like to get my array back as array or in some kind of sequence (like I would get on tokenizer)
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about looping through the set returned by map.keySet ?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your keys are arrays (which may or may not be what you really want), and the key set will be a set of arrays--that appears to be what you're getting.

Things like "[Ljava.lang.String..." aren't "gibberish"--that's a default toString() method, and is an array of Strings.
 
Jukka Kuusamo
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it's set of arrays. Now how could I read this array

I was just wondering that when I print it as toString it prints me an array, when I try to tokenizer it, which could be one way to use this non-array array, it thing just messes thing up.


Oh and yes it is gibberish if it isn't meant for human to understand
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no "non-array array"--it's an array. You have a set of arrays. Did you see Christophe's answer? Get the array from the key set. Then do whatever you want with it.

(And it *is* designed for a human to read; see these examples--sorry I can't find the correct reference off the top of my head.)
 
Jukka Kuusamo
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds good. How can I get it from set?
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jukka Kuusamo wrote:Sounds good. How can I get it from set?


Take a look at the java.util.Set API, which will likely lead you to the java.util.Iterator API.

Henry
 
Rob Spoor
Sheriff
Pie
Posts: 20393
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On a side note, it is a bad idea to use any highly mutable object (like Lists, Sets, Collections) as keys of a Map. The return values of the methods used to look them up again (hashCode + equals for (Linked)HashMap, compareTo / Comparator.compare for TreeMap) are very likely to change, therefore making it impossible to use methods like get, containsKey and other similar methods. It even allows you to use the very same object as two different keys. For instance:
 
Jukka Kuusamo
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well now I got it. I didn't really know how to walk though ArrayList.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic