Re: How do I get a String[] from a Map<String,Object> keys ?



In article <1183385127.693826.270170@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Jerome Eteve <jerome.eteve@xxxxxxxxx> wrote:

I all.
I have a

Map<String,Float> foo = ....

And the following line of code a couple of instructions after:

String[] fields = (String[])(foo.keySet().toArray()) ;

But at the runtime, I have a class cast exception telling me that it's
not possible to cast an Object down to a String.

How can I do to have an array of strings from the foo map key set ?

Thanks for your help.

Revisit the API and you'll find that the Set method toArray() explicitly
returns an Object array. But there's an alternative method which
returns an array of the type used in the Set. Try that one.
--
Steve W. Jackson
Montgomery, Alabama
.



Relevant Pages

  • Re: Returning a string array from a function
    ... I'd like to return an string array from a function so ... E.g. "total" only gets found out inside foo. ... to avoid storing past the end of the sptr[] array if `total' ...
    (comp.lang.c)
  • Re: why doesnt this compile
    ... Above, foo return array, but s is just a string. ... Private foo1() As String ...
    (microsoft.public.vb.general.discussion)
  • Re: String to array as command line
    ... ARGV array variable. ... def command_line string ... p command_line(' foo bar foobar ') ...
    (comp.lang.ruby)
  • Re: String parsing?
    ... I am trying to parse ... a string into an array. ... Array= foo ...
    (comp.lang.ruby)
  • Re: Forth Frustrations
    ... If you have a word that accepts a string then it's easy to get the ... we could do "FOO to tell the compiler to keep FOO ready, ... The address was HERE after the child was completed. ... lay down the two literals and then the execute, ...
    (comp.lang.forth)