Immutable maps Implemented by using a list-based data structure. The Scala List class holds a sequenced, linear list of items. We must import
scala.collection.mutable.ListMap for ListMap. ListMap collection used only for a small number of elements.
var listMapName = ListMap("k1"->"v1", "k2"->"v2", "k3"->"v3", ...)
Here, k is key and v is value.
Operaion performed by ListMap
Creating an ListMap:
In below code we can see a ListMap is created with values.
Map(C -> Csharp, S -> Scala, J -> Java)
Adding and accessing elements :
A ListMap is created, add elements and access elements also performed.
J -> Java C -> Csharp S -> Scala Scala P -> Perl C -> Csharp J -> Java S -> Scala
Removing an element from ListMap :
A ListMap is created than removing an element is performed using – sign. Below is the example to removing an element from ListMap.
J -> Java C -> Csharp S -> Scala After Removing J -> Java S -> Scala
Creating an empty ListMap:
An empty ListMap is created either by calling its constructor or using ListMap.empty method.
- Scala Tutorial – Learn Scala with Step By Step Guide
- Scala short <(x: Short): Boolean
- Scala short <(x: Char): Boolean
- Scala Extractors
- Scala | Partially Applied functions
- Scala String indexOf(String str) method with example
- Scala String contentEquals() method with example
- Scala Keywords
- Scala Int /(x: Int) method with example
- Scala Int /(x: Short) method with example
- Program to print Java Set of characters in Scala
- Scala Map size() method with example
- Scala SortedMap addString() method with a start, a separator and an end with example
- Scala Iterator addString() method with example
- Scala String substring(int beginIndex, int endIndex) method with example
- Scala | Functions Call-by-Name
- Program to convert Java list to an iterator in Scala
- Scala Set &() method with example
- Scala | Type Inference
- Program to convert Java set of Shorts to an Indexed Sequence in Scala
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.