3

I have a really simple/dumb question.

I have a variable returned from a spark dataframe that looks like this:

Any = WrappedArray(101, 11, 119, 141, 238, 64, 45, 268, 31, 63, 86, 23, 24, 420, ... 

All I want to do is cast this as a normal array so I can iterate through the integers. Even if I can just get it to the WrappedArray type, I can get to array from there.

nont
  • 9,322
  • 7
  • 62
  • 82
johnnydonna
  • 63
  • 1
  • 3

1 Answers1

5
    val w : WrappedArray[Int] = 1 to 10 toArray

    val a : Any = w  //a is now just like the variable you've got

    //cast the Any to a Wrapped array. Probably want to do this inside a try/catch 
    val wrapped = a.asInstanceOf[WrappedArray[Int]]
    wrapped.foreach{ i => println(i) }
nont
  • 9,322
  • 7
  • 62
  • 82