wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes how to store map value in string array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to store map value in string array" Watch "how to store map value in string array" New topic
Author

how to store map value in string array

vijayakumar durai
Ranch Hand

Joined: Aug 18, 2008
Posts: 153
can anybody tell how to store map value in string array


it will give class cast exception




thanks in advance
vijayakumar durai
Ranch Hand

Joined: Aug 18, 2008
Posts: 153
how to convert map value to array?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61084
    
  66

Please take the time to choose the correct forum for your posts. This forum is for questions on JSP.

For more information, please read this.

This post has been moved to a more appropriate forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

First, you're casting the contents of the map to the type "array of String." Are you sure the values in the Map are String arrays themselves, and not (for example) just Strings?

Secondly, you've allocated a String array which is appropriate for storing one String for each value in the map; then you're iterating over the map and trying to replace that array, over and over, with one extracted from the map. That's definitely not right.

If the values are Strings, and you're just trying to get them in an array, you might try something like

String[] toId = map.values().toArray(new String[map.size()]);


[Jess in Action][AskingGoodQuestions]
vijayakumar durai
Ranch Hand

Joined: Aug 18, 2008
Posts: 153
i am storing the map value in arraylist




can i able to convert into array?
Neha Kathuriaa
Greenhorn

Joined: Sep 16, 2008
Posts: 25

.Hop this is what you were looking for.
Reply please

[edit]Add code tags and delete excess whitespace. CR[/edit]
[ November 20, 2008: Message edited by: Campbell Ritchie ]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38463
    
  23
Thank you for the reply. Please always use the code button; it maintains indentation. I have edited your post so you can see how much easier it is to read.

I suspect your solution may not work, however. You will end up with an array full of the last value several times. There is however a simple way to correct that.

And please use System.err for printing Exception messages, not System.out.
vijayakumar durai
Ranch Hand

Joined: Aug 18, 2008
Posts: 153
thanks neha :roll: its working fine
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to store map value in string array