Map.contains – It checks that if a given key exists in the map or not.Map.++() – It is used to concatenate two or more maps.Values in numbers are: MapLike (10, 20, 30, 40) Println( "Values in numbers are : " + numbers.values ) Println( "Keys in Numbers are : " + numbers.keys ) It returns true if the map is empty otherwise false. It returns an iterable containing each value in the map. It returns an iterable containing each key in the map. Basic Operations on Map:Īll operations on maps can be expressed in terms of the following three methods: Learn more about operators through our blog on Scala Operators. var I:Map = Map() // Creates empty hash table whose values are integers and keys are string type If you want to use an immutable map then use Map and if you want to use a mutable map the use mutable. Scala Online Training provides mutable and immutable versions of Map. It is a collection of key/value pairs where keys are unique and value is retrieved according to the key. List.reverse – It is used to reverse the list elements.List.tabulate() – It converts the list in tabular form.List.fill() – It creates a list that contains the same element.ncat() – It is used to perform concatenation of two lists.Println( "Check data is empty or not : " + data.isEmpty )Īre you interested in learning Scala from experts? Enroll in our Scala training in Singapore now! Println( "Check number is empty or not : " + numbers.isEmpty ) Println( "Tail of Number is : " + numebrs.tail ) Println( "Head of Number is : " + numbers.head ) It returns a list consisting of all elements except the first. You can also define the list as follows: val numbers = 10 :: (20 :: (30 :: (40 :: Nil)))įor simplicity you can define the above list as follows:- val numbers = 10 :: 20 :: 30 :: 40 :: Nil That is, x:: xs represents a list whose first element is x, which is followed by list xs. The infix operator:: expresses list extension. Val empty: List = List() // Empty ListĬheck out the Scala certification blog! List Constructors –Īll lists are built from two more fundamental constructors that are Nil and.Nil represents an empty list. val numbers: List = List(10, 20, 30 ,40) //List of Integers The method:: pronounced cons transforms an object and a list into a new list whose head is the object and whose tail is the first list. The empty list is specified by Nil which is an object that represents an empty list. If the list contains t types of elements then it can be represented as – List List is a collection of similar types of elements which are immutable.
0 Comments
Leave a Reply. |