Adam Davies
Adam Davies

Reputation: 2802

Scala empty a list

I have a member variable in a class:

val options = mutable.LinkedList[SelectOption]()

I latter then populate this list from the database.

At some point I want to refresh the list. How do I empty it?

In java:

options.clear();

Is there an equivalent in Scala?

Upvotes: 7

Views: 835

Answers (1)

Daniel C. Sobral
Daniel C. Sobral

Reputation: 297155

Do not use LinkedList. That is a low level collection which provides a data structure that can be manipulated at user's will... and responsibility.

Instead, use one of the Buffer classes, which have the clear method. This method, by the way, is inherited from the Clearable trait, so you can just look at classes that extend Clearable.

Upvotes: 12

Related Questions