Javatpoint Logo
Javatpoint Logo

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

Test it Now

Output:

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

Example 2

Test it Now

Output:

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



Help Others, Please Share

facebook twitter pinterest