`
ddandyy
  • 浏览: 211388 次
  • 性别: Icon_minigender_1
  • 来自: 目前上海
社区版块
存档分类
最新评论

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

 
阅读更多
两种方法

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)) {

}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics