I have this snippet:
final Stream<String>stream = getStream().filter(a->StringUtils.contains(a,"http"));
stream.filter(a->true);//LINE PROBLEM I JUST THOUGHT THAT THIS WOULD JUST IGNORE
System.out.println(stream.count());
But throws:
Exception in thread "main" java.lang.IllegalStateException: stream has already been operated upon or closed
I know that streams can be used just once but what is wrong with this line? It's consuming the stream?
stream.filter(a->true);//NOT A TERMINAL OPERATION A INTERMEDIATE OPERATION
If I ripped it of just use my code like this
System.out.println(stream.filter(a->true).count());
Not exception is thrown.
If I use this code NotException is Thrown.
Stream<String>stream = getStream().filter(a->StringUtils.contains(a,"http"));
stream = stream.filter(a->true);
System.out.println(stream.count());
But why filter is throwing exception and IS NOT A TERMINAL OPERATION?
I am using just the simplest code to get the idea.
I am using Netbeans 8.2 with Java 8 update 122 also tested in Intellij Idea 2018 Ultimate.