Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
The contains() method of Java AbstractCollection class
The contains() method of the AbstractCollection class checks whether an element is in the AbstractCollection or not. It returns a Boolean i.e. TRUE if the element is in the collection, else FALSE is returned.
The syntax is as follows:
public boolean contains(Object ele)
Here, ele is the element to be checked for existence.
To work with AbstractCollection class in Java, import the following package:
import java.util.AbstractCollection;
The following is an example to implement AbstractCollection contains() method in Java:
Example
import java.util.ArrayList;
import java.util.AbstractCollection;
public class Demo {
public static void main(String[] args) {
AbstractCollection<Object> absCollection = new ArrayList<Object>();
absCollection.add("Football");
absCollection.add("Tennis");
absCollection.add("Badminton");
absCollection.add("Cricket");
absCollection.add("Basketball");
absCollection.add("Golf");
absCollection.add("BaseBall");
absCollection.add("Handball");
System.out.println("AbstractCollection = " + absCollection);
System.out.println("The elements exist in the Collection? = "+ absCollection.contains("Golf"));
}
}
Output
AbstractCollection = [Football, Tennis, Badminton, Cricket, Basketball, Golf, BaseBall, Handball] The elements exist in the Collection? = true
Advertisements