Created
July 21, 2015 20:45
-
-
Save devinrsmith/2d806402e3b2220ec0e2 to your computer and use it in GitHub Desktop.
Testing spliterator visibility
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Spliterator; | |
import java.util.function.Function; | |
import java.util.stream.Collectors; | |
import java.util.stream.Stream; | |
import java.util.stream.StreamSupport; | |
/** | |
* Created by dsmith on 7/21/15. | |
*/ | |
public class SpliteratorTest { | |
public static void main(String[] args) { | |
System.out.println("Test 1"); | |
test1(); | |
System.out.println("Test 2"); | |
test2(); | |
} | |
public static void test1() { | |
final Spliterator<String> spliterator1 = Stream.of("a", "b", "c", "d", "e", "f").spliterator(); | |
StreamSupport.stream(spliterator1, false). | |
limit(3). | |
collect(Collectors.toList()); | |
System.out.println("spliterator1.estimateSize() = " + spliterator1.estimateSize()); | |
} | |
public static void test2() { | |
final Spliterator<String> spliterator1 = Stream.of("a", "b", "c", "d", "e", "f").spliterator(); | |
final Spliterator<String> spliterator2 = Stream.of("1", "2", "3", "4", "5", "6").spliterator(); | |
Stream.of(StreamSupport.stream(spliterator1, false), StreamSupport.stream(spliterator2, false)). | |
flatMap(Function.identity()). | |
limit(3). | |
collect(Collectors.toList()); | |
System.out.println("spliterator1.estimateSize() = " + spliterator1.estimateSize()); | |
System.out.println("spliterator2.estimateSize() = " + spliterator2.estimateSize()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Outputs: