0

for example i have given a mixed type array as follows , i'm trying to print the each and every element in the array, im able to print Array of Arrays but this one is very tricky .

val r = Array(1,2,3,4,Array(2,3,45,6,Array(4,4,6,7)))

i need to print this nested one.

3
  • 10
    Why would someone make such a data structure? Commented Dec 18, 2016 at 13:37
  • experimentation Commented Dec 19, 2016 at 4:57
  • it works, i didnt think abt a recursive way Commented Dec 19, 2016 at 5:34

1 Answer 1

5

You could do something like this

def printMixedArray(a: Array[_]) : Unit = a.foreach{ 
   case a: Array[_] => printMixedArray(a)
   case b => println(b) 
} 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.