Table of Contents
- Scala List class introduction
- Notes about the following List examples
- CREATE: Create a new List with initial elements
- CREATE: Create a new List by populating it
- READ: How to access Scala List elements
- UPDATE: How to add (append and prepend) elements to a List
- UPDATE: How to “update” List elements
- DELETE: Filtering methods (how to “remove” elements from a List)
- MORE: Transformer methods
- MORE: Informational and mathematical methods
- MORE: Grouping methods
- MORE: Looping over a List with for and foreach
- A few things you can do with a List of Options
- Scala List summary
This page contains a large collection of examples of how to use the methods on the Scala List
class.
Scala List class introduction
The List class is an immutable, linear, linked-list class. It’s very efficient when it makes sense for your algorithms to (a) prepend all new elements, (b) work with it in terms of its head and tail elements, and (c) use functional methods that traverse the list from beginning to end, such as filter
, map
, foldLeft
, reduceLeft
.