首页 > 解决方案 > 类型不匹配:无法从 int 转换为 Integer

问题描述

我正在尝试做一个二维数组。

这是代码: public class TwoDimensionalArray {

public static void main(String[] args) {
    
    Integer str[][]=new Integer[3][3];

    
    str [0][0]=10; the error is here 'cannot convert from int to integer'
    

标签: javaarraysstring

解决方案


Integer 和 int 是不同的数据类型。如果您不指定,则该语言假定为 int。我会解决它如下:

public static void main(String[] args) {

    Integer str[][]=new Integer[3][3];
    Integer myInt = 10;
    str [0][0]=myInt;
}

推荐阅读