我正在尝试了解 SplitIterator 的功能并遇到以下情况:
public static void main(String[] args) {
Set<Integer> l = new HashSet();
l.add(1);
l.add(2);
l.add(3);
Spliterator<Integer> s= (Spliterator<Integer>) l.spliterator();
Spliterator<Integer> s1=s.trySplit();
while(s1.tryAdvance(n -> {System.out.print(n+" ");System.out.println("estimateSize "+s.estimateSize()+" getexactsizeifknown "+s.getExactSizeIfKnown());}));
为什么该方法getexactsizeifknown
返回-1
for HashSet
?
对于其他集合,它返回与estimateSIze()