0

I tried this:

var myQueue = scala.collection.mutable.Queue(myList)

Where list contains elements, let's say: List(1,2,3,4,5)

I want a queue with the same elements with the list such as: Queue(1,2,3,4,5). But what I got is: Queue(List(1, 2, 3, 4, 5))

Any idea?

1
  • 2
    btw: you should avoid using var and mutable collections when programming Scala. There is (almost) always a way to do it in another way! Commented Nov 3, 2017 at 16:27

1 Answer 1

1

Pass the list as a vararg:

val myList = List(1, 2, 3, 4, 5)

val myQueue = scala.collection.mutable.Queue(myList: _*)
// Queue(1, 2, 3, 4, 5)
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.