1z0-809 practice questions, page 9 of 10, with answer review and explanations.
Question 41
Given the code fragment: List str = Arrays.asList ("my", "pen", "is", "your', "pen"); Predicate test = s -> { int i = 0; boolean result = s.contains ("pen"); System.out.print(i++) + ":"); return result; }; str.stream() .filter(test) .findFirst() .ifPresent(System.out ::print); What is the result?
0 : 0 : pen
0 : 1 : pen
0 : 0 : 0 : 0 : 0 : pen
0 : 1 : 2 : 3 : 4 :
A compilation error occurs.
Question 42
Given the code fragment: List empDetails = Arrays.asList("100, Robin, HR", "200, Mary, AdminServices", "101, Peter, HR"); empDetails.stream() .filter(s-> s.contains("1")) .sorted() .forEach(System.out::println); //line n1 What is the result?
Given: interface Rideable {Car getCar (String name); } class Car { private String name; public Car (String name) { this.name = name; } } Which code fragment creates an instance of Car?
Car auto = Car ("MyCar"): : new;
Car auto = Car : : new; Car vehicle = auto : : getCar("MyCar");
Rideable rider = Car : : new; Car vehicle = rider.getCar("MyCar");
Car vehicle = Rideable : : new : : getCar("MyCar");
Question 44
Which statement is true about the single abstract method of the java.util.function.Function interface?
It accepts one argument and returns void.
It accepts one argument and returns boolean.
It accepts one argument and always produces a result of the same type as the argument.
It accepts an argument and produces a result of any data type.
Question 45
Which statement is true about the DriverManager class?
It returns an instance of database.
It executes SQL statements against the database.
It loads the database driver class mentioned in the jdbc.drivers property
it is written by different vendors for their specific database.