The size() method of List interface in Java is used to get the number of elements in this list. That is, this method returns the count of elements present in this list container.
public int size()
Parameters: This method does not takes any parameters.
Return Value: This method returns the number of elements in this list.
Below are the examples to illustrate the size() method.
Before operation: [1, 2, 3, 4, 5] Size of list = 5
Before operation: [Geeks, for, Geeks] Size of list = 3
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.