java - Where is the implementation of the filter() method in the Stream interface ?? -



java - Where is the implementation of the filter() method in the Stream<T> interface ?? -

good day dears

i have below simple code

class app { public static void main(string[] args) { arraylist<integer> mylist = new arraylist<>(); mylist.add(7); mylist.add(18); mylist.add(10); mylist.add(24); mylist.add(17); mylist.add(5); stream<integer> stream = mylist.stream(); stream = stream.filter(n -> n > 10); // returns stream of elements more 10 stream.foreach(n -> system.out.print(n + " ")); } }

the function of code filters invoking stream , print elements more 10. test method in predicate .. ok .. implementation filter() method homecoming "stream" more 10 .. don't understand ... !! question in way applies foreach() method ..how iterate throw stream ..

since filter() , foreach() methods abstract in interface stream , has no implementation .

please need explanation ..

java.util.stream.referencepipline implementing stream<t>.filter().

@override public final stream<p_out> filter(predicate<? super p_out> predicate) { objects.requirenonnull(predicate); homecoming new statelessop<p_out, p_out>(this, streamshape.reference, streamopflag.not_sized) { @override sink<p_out> opwrapsink(int flags, sink<p_out> sink) { homecoming new sink.chainedreference<p_out, p_out>(sink) { @override public void begin(long size) { downstream.begin(-1); } @override public void accept(p_out u) { if (predicate.test(u)) downstream.accept(u); } }; } }; }

java java-8 abstract java-stream java-api

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -