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.
- 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
- Scala Int <(x: Char) method with example