Reputation: 8358
In a Scala project, I need a simple, mutable queue data structure where I can append items on one end and take out items on the other (i.e. FIFO). Now, I'm not sure whether I should use the plain old LinkedList
from Java, or Scala's DoubleLinkedList
. What are the relative advantages of these two? Should I always prefer the DoubleLinkedList
, or is there any good reason to use LinkedList
? Also, are there any other options worth considering?
Upvotes: 1
Views: 296
Reputation: 9954
If you want to interface with Java code it is perhaps an advantage to use the LinkedList
.
Else if you only have scala code then go for the DoubleLinkedList
as it has many advantages in scala.
Upvotes: 1
Reputation: 12998
As for other options, consider using a scala.collection.mutable.Queue. There is even an immutable version: scala.collection.immutable.Queue.
A quote from the doc:
Queue objects implement data structures that allow to insert and retrieve elements in a first-in-first-out (FIFO) manner.
so if your intention is to have a FIFO/Queue, the class name Queue
could be easier to read/maintain than any LinkedList
Upvotes: 5