我需要在arraylist 中找到一个整数数据吗? [英] i need to find a integer data in arraylist?

查看:24
本文介绍了我需要在arraylist 中找到一个整数数据吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Arraylist.如果用户第二次输入相同的数字,我想向用户显示.为此,我需要找到 Arraylist 是否拥有.

I have an Arraylist. If user enter the same number secondly I want to show to user. For this I need to find Arraylist have it or not.

我希望我说清楚了.

推荐答案

如果您正在检查某个值是否存储在 ArrayList 中,您可以使用 contains() 方法,如果对象在列表中,则返回 true,否则返回 false.

If you are checking to see if some value is stored in an ArrayList you can use the contains() method, this will return true if the object is in the list, false otherwise.

ArrayList<Integer> intList = new ArrayList<>();

intList.add(5);
intList.add(7);
intList.add(3);
intList.add(-2);

intList.contains(-1); //returns false
intList.contains(3); //returns true

这篇关于我需要在arraylist 中找到一个整数数据吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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