判断一个数字是否在一个数组中

两种方法

1。在一个数组中
int[] aa = new int[]{1,2,3,4,5};

int ii = 3;
if (Arrays.binarySearch(aa,ii) >= 0) {

}



2。在一个list中
List aaList = new ArrayList();
aaList.add(new Integer(0));
aaList.add(new Integer(1));
aaList.add(new Integer(2));
Integer aaInt = new Integer(3);
if (aaList.contains(aaInt)) {

}

你可能感兴趣的:(数组)