【问题标题】:Hashmap put method wont Compile with char[][] type?Hashmap put 方法不会用 char[][] 类型编译?
【发布时间】:2014-05-09 01:29:24
【问题描述】:

field.put 方法无法编译。我不断收到一个错误,即板的类型需要是 char[][] 但它已经是。 有人可以帮我解决这个问题吗?

import java.util.HashMap;


    public class Field {

        private HashMap<String, char[][]> field;


        public Field(Integer xAs, Integer yAs, char[][] board ,Integer difficulty){

            for(int i = 0; i < board.length; i++){

                char x = 'A';
                char r = 1;

                for(int j = 0; j < board[i].length; j++){

                    if(i == 0){

                        field.put(x + "" , board[i][j]);

                    }
                    if(j == board[i].length - 1){
                        field.add(r + "", board[i][j]);


                    }
                    else{
                        field.add(x + r, board[i][j]);
                    }



                }
            }

        }

【问题讨论】:

    标签: java eclipse hashmap multidimensional-array


    【解决方案1】:

    board[i][j]char,而不是 char[][],您需要将整个板添加到 Map 或将声明更改为 HashMap&lt;String, Character&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-17
      • 1970-01-01
      • 2014-10-29
      • 1970-01-01
      • 2020-06-26
      • 2018-08-25
      • 1970-01-01
      • 2019-09-23
      相关资源
      最近更新 更多