Javatpoint Logo
Javatpoint Logo

Scala List

List is used to store ordered elements. It extends LinearSeq trait. It is a class for immutable linked lists. This class is good for last-in-first-out (LIFO), stack-like access patterns.

It maintains order of elements and can contain duplicates elements also.


Scala List Example

In this example, we have created two lists. Here, both lists have different syntax to create list.

Output:

List(1, 8, 5, 6, 9, 58, 23, 15, 4)
List(1, 8, 5, 6, 9, 58, 23, 15, 4)

Scala List Example: Applying Predefined Methods

Output:

Elements: 1 8 5 6 9 58 23 15 4 
Element at 2 index: 5
Element after merging list and list2: 1 8 5 6 9 58 23 15 4 88 100 
Element after sorting list3: 1 4 5 6 8 9 15 23 58 88 100 
Elements in reverse order of list5: 100 88 4 15 23 58 9 6 5 8 1
Next TopicScala Queue




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA