Java Spliterator estimateSize() Method

The estimateSize() method of Java Interface Spliterator is used to get an estimate of the number of elements remaining to iterate or returns Long.MAX_VALUE if infinite, unknown, or too expensive to compute.

Syntax

Following is the declaration of estimateSize() method-

Parameter

This method does not accept any parameter.

Return

The estimateSize() method returns the estimated size of elements or Long.MAX_VALUE if infinite, unknown, or too expensive to compute.

Exceptions

NA

Compatibility Version

Java 1.8 and above

Example 1

Output:

Estimate size of ArrayList: 4
Elements of arraylist: 
1
-2
3
-4

Example 2

Output:

Estimate size of List: 7

Example 3

Output:

Estimate size: 3
Name present in List:
Rahul
Rohit
Surya
Again Estimate size is: 0