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.
I hope I made myself clear.
An element in an ArrayList can be searched using the method java. util. ArrayList. indexOf().
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 can not be used for primitive types, like int, char, etc.
An element can be retrieved from the ArrayList in Java by using the java. util. ArrayList. get() method.
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
You might want to use ArrayList.contains()
to check if the element is in the ArrayList
or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With