Javatpoint Logo
Javatpoint Logo

Java Collection contains() Method

The contains() method of Java Collection Interface returns a Boolean value 'true', if it contains the specified element in the collection.

Syntax

Parameters

The parameter 'o' represents the element whose occurrence in this collection is to be tested.

Throws

ClassCastException- if the type of the specified element is not compatible with this collection.

NullPointerException- if the specified element is null and this collection does not allow null elements.

Returns

The contains() method returns Boolean value 'true' if this collection contains all the specified element else it returns false.

Example 1

Test it Now

Output:

Rama is present

Example 2

Output:

Q. Enter smallest even prime no
Ans 2
Your answer is correct.

Example 3

Test it Now

Output:

Geeta is present on 12.08.18
Next TopicJava Collection





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA