【发布时间】:2018-07-21 05:42:18
【问题描述】:
我有类似的东西
//constructors
public IntBag() {
myBag = new Integer[500];
}
public boolean contains( int aNumber) {
if ( bag[aNumber] == null )
return false;
else
return true; }
public int size() {
int num;
num= 0; //Number of filled slot
for( int j = 0; j < myBag.length; j++) {
if ( myBag.contains(j) )
num++; }
return num; }
我收到一个错误 错误:找不到符号 符号:方法包含(int) 位置:java.lang.Integer[]类型的变量包
我该如何解决这个问题?
【问题讨论】:
-
那个方法我已经写好了
-
bag是Integers 的数组。你可以使用Arrays.asList( bag ).contains( i ) -
为什么它不能以这种方式工作
-
“为什么它不能以这种方式工作” - 因为数组没有称为
contains的方法。 -
是什么让你认为它应该这样做?