Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to store map value in string array

 
vijayakumar durai
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anybody tell how to store map value in string array


it will give class cast exception




thanks in advance
 
vijayakumar durai
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to convert map value to array?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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()]);
 
vijayakumar durai
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am storing the map value in arraylist




can i able to convert into array?
 
Neha Kathuriaa
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

.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
Pie
Posts: 50241
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks neha :roll: its working fine
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic