Question: Q 5 . ( a ) Streams from java.util.stream allow for processing of collections in a way that is declarative, composable, and parallelizable. Explain what

Q5.(a) Streams from java.util.stream allow for processing of collections in a way that is declarative, composable, and parallelizable. Explain what is meant by this using examples where appropriate. 6 MARKS (b) Suppose you have a collection of Car objects (i.e., List cars) where a car has the following interface: public interface Car { public String getMake(); public String getModel(); public double getEngineSize(); public String getRegistrationNumber(); } Illustrate using Java code how you would use the Java Streams API to (i) get a List of the registration numbers of the cars in the collection. 5 MARKS (ii) Count the number of cars that have an engine size larger than 2.0 litres. 5 MARKS (iii) Get a List of three car models that begin with the letter T.6 MARKS (iv) Prints the cars to the console (you can assume that concrete Car classes have an appropriate toString() implementation. 3 MARKS

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!