0

I try to append an array element inside another array dynamically(by query result) as follows.But the element does not append in the array. What is the proper way to append an array inside another array?

var content:Array[Array[String]]=Array(Array())

content(0)=Array("h1","h2","h3","h4","h5","h6","h7","h8","h9")

val myResult = for(ts <- myQueryList) yield (
    content+:Array(e1,e2,e3,e4,e5,e6,e7,e8,e9)
)
0

2 Answers 2

2

The problem is that the operation creates a new array that you need to reassign to content like this:

content=content+:Array(e1,e2,e3,e4,e5,e6,e7,e8,e9)

or a little bit cleaner:

content ++= Array(e1,e2,e3,e4,e5,e6,e7,e8,e9)

I hope this is what you want, it's not too clear what you want to do from your code.

Sign up to request clarification or add additional context in comments.

Comments

0

Is there a particular reason you don't want to use Array.concat?

Something like:

myResult = Array.concat(content, myQueryList)

(Provided myQueryList is an Array[Array[String]]).

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.