0% found this document useful (0 votes)
13 views2 pages

Java Collection Interface Methods Guide

The Collection interface is the foundational interface of the Java Collections Framework, defining essential methods for all collection types like List, Set, and Queue. Key methods include add, remove, clear, size, isEmpty, and contains, which facilitate various operations on collections. Common implementing classes include ArrayList, HashSet, and LinkedList.

Uploaded by

Jaya Ram
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Java Collection Interface Methods Guide

The Collection interface is the foundational interface of the Java Collections Framework, defining essential methods for all collection types like List, Set, and Queue. Key methods include add, remove, clear, size, isEmpty, and contains, which facilitate various operations on collections. Common implementing classes include ArrayList, HashSet, and LinkedList.

Uploaded by

Jaya Ram
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java Collection Interface Methods - Cheat Sheet

What is Collection Interface?

The Collection interface is the root interface of the Java Collections Framework. It defines basic methods that

all collections like List, Set, and Queue must implement. Common classes that implement Collection include

ArrayList, HashSet, LinkedList, etc.

Located in: [Link]<E>

add(E e)

Adds an element to the collection. Returns true if the collection changed.

addAll(Collection<? extends E> c)

Adds all elements from another collection.

remove(Object o)

Removes a single instance of the specified element.

removeAll(Collection<?> c)

Removes all elements in the collection that are also in the specified collection.

retainAll(Collection<?> c)

Keeps only the elements that are also in the specified collection.

clear()

Removes all elements from the collection.

size()

Returns the number of elements.


Java Collection Interface Methods - Cheat Sheet

isEmpty()

Returns true if the collection has no elements.

contains(Object o)

Returns true if the collection contains the specified element.

containsAll(Collection<?> c)

Returns true if the collection contains all elements of the specified collection.

iterator()

Returns an iterator over the elements.

toArray()

Returns an array containing all elements of the collection.

You might also like