Scala - How to create a range of characters as a Scala Array? Code Example

The code for How to create a range of characters as a Scala Array?

var x = ('A' to 'R').toArray

// Note: Array.range always returns Array[Int]
// Thus, we need to convert from Int to Char
// while printing (if required) using .toChar
var y = Array.range('R', 'Z')

// printing the values
for(i <- x) print(i)

println()

for(i <- y) print((i).toChar)

/*
Output:
ABCDEFGHIJKLMNOPQR
RSTUVWXY
*/
Code by IncludeHelp, on August 10, 2022 23:27

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.