字符串数组和int数组映射到2D字符串数组

时间:2018-02-24 12:42:33

标签: java arrays string

我需要找出一种方法将下面的地图作为String [] []

返回
public class Board {
   private Map<String[], int[]> rows;
   private String code;
   private int tries;

public Board(String code, int size) {
    this.tries = 0;
    this.code = code;
    this.rows = new HashMap<>();
}

public Map<String[], int[]> getRows() {
    return rows;
}

它来自这个类

initialize

1 个答案:

答案 0 :(得分:1)

public class Board {
   private Map<String, int[][]> rows;
   private String code;
   private int tries;

public Board(String code, int size) {
    this.code = code;
    this.tries = 0;
    this.rows = new HashMap<>(size);
}

public Map<String, int[][]> getRows(String code) {
    return rows !=null ? rows.get(code):null;
}

public void setRows(String code, int[][] data) {
    if(rows == null)
       rows = new HashMap<>();

    rows.put(code,data);
}