Swift中矩阵的Java转换

Swift中矩阵的Java转换,java,swift,matrix,Java,Swift,Matrix,我正在尝试将下面的Swift代码转换为Java,对于数组中的数组是如何工作的,我有点困惑。为了在Java中的数组中添加值,我正在尝试: if(level == 0){ for(int i = 0; i < value; i++){ mRep[level][i] = value; } else{ for(int n : children){ travers(n); mRep[] } } matrix

我正在尝试将下面的
Swift
代码转换为Java,对于数组中的数组是如何工作的,我有点困惑。为了在Java中的数组中添加值,我正在尝试:

if(level == 0){
    for(int i = 0; i < value; i++){
      mRep[level][i] = value;
    } else{
      for(int n : children){
        travers(n);
        mRep[]
      }
    }

matrixRepresentation
不是一个由
int
组成的二维数组吗?
int[][]
?我的等价物是
mRep
。只是不确定他们用来在Swift中传递值的结构
// head of the tree
  var head : Node
  var matrixRepresentation : [[Int]] = [[]]
  var nodeCount : Int = 0

  // constructor
  init(head: Node) {
    self.head = head
    self.head.expand()
    for x in 0...(head.matches-2) {
      matrixRepresentation.append([])
    }
    traverse(self.head)
  }

  // traverse tree to store data in a matrix
  // so that it can be displayed in a top down approach
  func traverse(node: Node) {
    var level = node.level
    var value = node.value
    var children = node.children

    if level == 0 {
      matrixRepresentation[level].append(value)
      nodeCount++
    }
    for n in children {
      traverse(n)
      matrixRepresentation[level+1].append(n.value)
      nodeCount++
    }
  }