Java Collection size() method

The size() method of Java Collection Interface returns the total count of the elements contained in this collection.

Syntax

Parameters

NA

Return Value

The size() method returns the total count of the elements present in this collection.

Example 1

Test it Now

Output:

The elements in Collection : [34, 12, 45]
Size of the collection 3

Example 2

Test it Now

Output:

Total alphabets : 26
collection : [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z]
Number of vowels : 5
Vowels : [a, e, i, o, u]

Example 3

Test it Now

Output:

The queue is empty.
Next TopicJava-Collection




Latest Courses