你如何创建一个整数的ArrayList? [英] How do you create an integer ArrayList?

查看:283
本文介绍了你如何创建一个整数的ArrayList?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建的ArrayList的Java中的数组。我已经通过以下方式宣布它:

I am trying to create an array of Arraylists in Java. I have declared it in the following way:

ArrayList[][][] arrayQ = new ArrayList[90][13][18];

for (int i = 0; i < 90; i++) {
  for (int j = 0; j < 13; j++) {
    for (int k = 0; k < 18; k++) {
      arrayQ[i][j][k] = new ArrayList<int>();
    }  
  } 
}

不过,添加&LT; INT&GT; 里面的while循环引发错误(我用遗憾的是不给我一个很好的错误消息IDE)

However, adding the <int> inside the while loop throws an error (the IDE I'm using unfortunately doesn't give me a very good error message).

什么是创建一个整数的ArrayList的正确方法?

What's the proper way to create an integer ArrayList?

推荐答案

Java集合只能容纳对象。 INT 是一个原始数据类型,并且不能在的ArrayList 例如举行。您需要使用整数来代替。

Java Collections can only hold objects. int is a primitive data type and cannot be held in an ArrayList for example. You need to use Integer instead.

这篇关于你如何创建一个整数的ArrayList?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆