In Scala an array of String can be converted to an array of Int, utilizing map function. Here, the strings of the stated array will be called by the map function which has a length method in it as its argument. Then this array of strings will return an array of integers, where these integers are the length of an each string stated in an array.
Now, lets see some examples below in order to understand it in details.
12 6 888
So, here the array of strings are transformed to an array of integers. And duplicate elements will also repeat.
0 1 2
Here, if there is one space in the string then the length is counted as one of there is no space then the length is zero and if there is two spaces then the length is two and so on.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.