Java - 返回二维数组值

时间:2017-03-23 16:20:20

标签: java arrays methods

我想返回2D数组的所有值。如果我使用带String类型的get方法,我怎么能返回它?

public class Data {
private final String[][] table;
public Data(){
    table = new String[][] {{"ID", "NAME"},
                         {"101", "A"},
                         {"102", "B"},
                         {"103", "C"},
                         {"104", "D"},
                         {"105", "E"}};
}

public String[][] get(){
    for (int i = 0; i < table.length; i++) {
        for (int j = 0; j < table[i].length; j++) {
            table[i][j] = table[i][j];
        }
    }
    return table;
}

public void displayMessage(){
    System.out.println(get());
}

}

0 个答案:

没有答案