Easy, just import the Guava lib into your XTend script. The Guava lib has multidimenional MultiSet in it.
Xtend and Arrays
-
28-11-2021 - |
Question
Does xtend support two-or more dimensional arrays? If yes: How can i create one and use it later on? I want to store Strings in these arrays and pass it to the files.
Solution 2
OTHER TIPS
Here is my solution that creates a matrix of integers (rows x cols). The only disadvantage is that each row is allocated separately in a loop.
@Pure
static def int[][] newIntArrayOfSize(int nrow, int ncol) {
newArrayOfSize(nrow).map[ newIntArrayOfSize(ncol) ]
}
Demo:
// allocate 3 rows by 2 columns
val m = newIntArrayOfSize(3, 2)
// notice that indexes are starting from 0
// here setting value 5 on row=2, col=1
m.get(2).set(1, 5)
for(row : 0 .. 2) {
for(col : 0..1) {
print(m.get(row).get(col))
print("\t")
}
println()
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow