Issue
I want to create the following one with a fancy notation:
arrayOf(intArrayOf(4, 5), intArrayOf(5, 8), intArrayOf(1, 9), intArrayOf(8, 10), intArrayOf(1, 6))
at least, cannot I achieve something that looks as follows:
arrayOf<IntArray>((4, 5), (5, 8), (1, 9), (8, 10), (1, 6))
because it is pretty awkward to rewrite intArrayOf
for each row to put in.
Note that I do not ask for the following syntax I'm aware of which is used to initialize an empty matrix with values that are either same or following a common pattern.
val array = Array(row) { IntArray(column) }
Solution
If you simply don't like the wordiness of using intArrayOf
you could define a shorter name to do the same, for example
fun i(vararg e: Int) = intArrayOf(*e)
And then do
arrayOf(i(4, 5), i(5, 8), i(1, 9), i(8, 10), i(1, 6))
Answered By - Ivo Beckers
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.