Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 678
Adam Davies Avatar asked Jan 17 '13 14:01

Adam Davies


1 Answers

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.

like image 193
Daniel C. Sobral Avatar answered Nov 18 '22 13:11

Daniel C. Sobral