문제

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.

도움이 되었습니까?

해결책 2

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

다른 팁

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()
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top