![]() |
VOOZH | about |
Given a Collection in Java, the task is to find the length or size of the collection.
Examples:
Input: Array_List: [1, 2, 3,4] Output: 4 Input: Linked_List: [geeks, for, geeks] Output: 3
The Size of the different collections can be found with the size() method. This method returns the number of elements in this collection. This method does not take any parameters.
Below is the Implementation:
Example 1:
Size of list = 4 Array_List = [1, 2, 3, 3]
Example 2:
Size of the linkedlist = 3 Linkedlist = [GEEKS, FOR, GEEKS]