VOOZH about

URL: https://www.geeksforgeeks.org/java/how-to-get-a-size-of-collection-in-java/

⇱ How to Get a Size of Collection in Java? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Get a Size of Collection in Java?

Last Updated : 15 Oct, 2020

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:


Output
Size of list = 4
Array_List = [1, 2, 3, 3]

Example 2: 


Output
Size of the linkedlist = 3
Linkedlist = [GEEKS, FOR, GEEKS]
Comment
Article Tags: