Java Spliterator getExactSizeIfKnown() Method

The getExactSizeIfKnown() method of Java Interface Spliterator is used to get an estimateSize() of the SIZED spliterator, otherwise returns -1.

Syntax

Following is the declaration of getExactSizeIfKnown() method-

Parameter

This method does not accept any parameter.

Return

The getExactSizeIfKnown() method returns the estimateSize() of the spliterator, if known, otherwise returns -1.

Exceptions

NA

Compatibility Version

Java 1.8 and above

Example 1

Output:

Estimate size: 4
Exact size: 4
Elements of arraylist-- 
1001
-2001
3001
-4001

Example 2

Output:

Exact size before getting List elements: 3
Rahul
Nikki
Prem
Exact size after getting List elements: 0