Scala Int to(end: Int) method with example
The to(end: Int) method is utilized to return a range from the stated int to the ‘end’, which is given in the arguments list but here “step” is not specified in the arguments list.
Method Definition: def to(end: Int): Inclusive
Return Type: It returns the range.
Example #1:
// Scala program of Int to() // method // Creating object object GfG { // Main method def main(args : Array[String]) { // Applying to() method val result = 5 .to( 10 ) // Displays output println(result) } } |
chevron_right
filter_none
Output:
Range(5, 6, 7, 8, 9, 10)
Example #2:
// Scala program of Int to() // method // Creating object object GfG { // Main method def main(args : Array[String]) { // Applying to() method val result = 20 .to( 25 ) // Displays output println(result) } } |
chevron_right
filter_none
Output:
Range(20, 21, 22, 23, 24, 25)