• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting array back from map

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What about looping through the set returned by map.keySet ?
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds good. How can I get it from set?
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well now I got it. I didn't really know how to walk though ArrayList.
 
If you send is by car it's a shipment, but if by ship it's cargo. This tiny ad told me:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic