Range in Scala:
Selective range of many types such as numbers or characters in sequence that can be used in looping constructs.
Types of Ranges:
1.Number Ranges:
Selective range of numbers using to,until, and by kewords.
Example:
i)Selective range using to, until keyword:
Note:
Selective range of many types such as numbers or characters in sequence that can be used in looping constructs.
Types of Ranges:
- Number Ranges
- Alphabetical Ranges
1.Number Ranges:
Selective range of numbers using to,until, and by kewords.
Example:
i)Selective range using to, until keyword:
Note:
- to keyword to include the the last upper bound
- until keyword to exclude the last upper bound
ii)Range numbers 1 to 10 with increment of 3:
Note:
by keyword to increment by the number as opposed to the default value of 1.
2.Alphabetical Ranges:
Selective range of alphabets using to,until, and by kewords.
Example:
i)Selective range using to, until keyword:
Note:
- to keyword to include the the last upper bound character
- until keyword to exclude the last upper bound character
ii)Range characters 'A' to 'Z' with specified increment of 3:
Note:
by keyword to increment by the character as opposed to the default value of 1.
iii)Convert Scala Range into collections:
Sometimes we may need to convert the Range into some other data structure such as List, Set, Sequence or an Array.
Below, which uses methods called toList, toArray, toSet and toSeq functions to convert Range
Sometimes we may need to convert the Range into some other data structure such as List, Set, Sequence or an Array.
Below, which uses methods called toList, toArray, toSet and toSeq functions to convert Range
No comments:
Post a Comment