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.

Was it helpful?

Solution 2

Easy, just import the Guava lib into your XTend script. The Guava lib has multidimenional MultiSet in it.

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
scroll top