This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Getting array back from map

 
Greenhorn
Posts: 11
  • 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)
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
Sounds good. How can I get it from set?
 
author
Posts: 23879
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • 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
 
Sheriff
Posts: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • 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
  • 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.
 
Do you want ants? Because that's how you get ants. And a tiny ads:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic