5 Generics
5 Generics
obj.print();
} }
• OutputGfG 15
Collections in Java
• The Collection in Java is a framework that
provides an architecture to store and
manipulate the group of objects.
• Java Collections can achieve all the operations
that you perform on a data such as searching,
sorting, insertion, manipulation, and deletion.
2 public Object next() It returns the element and moves the cursor
pointer to the next element.
Constructors of ArrayList
Constructor Description
ArrayList(int capacity) It is used to build an array list that has the specified
initial capacity.
Methods of ArrayList
Method Description
Constructor Description
This method is used to add a specific element to the set. The function adds the element
add(element) only if the specified element is not already present in the set else the function returns
False if the element is already present in the Set.
This method is used to append all of the elements from the mentioned collection to the
addAll(collection)
existing set. The elements are added randomly without following any specific order.
This method is used to remove all the elements from the set but not delete the set. The
clear()
reference for the set still exists.
contains(element) This method is used to check whether a specific element is present in the Set or not.
This method is used to check whether the set contains all the elements present in the
containsAll(collectio
given collection or not. This method returns true if the set contains all the elements and
n)
returns false if any of the elements are missing.
Method Description
This method is used to return the iterator of the set. The elements from the set are returned
iterator()
in a random order.