Given the code fragment:
List
System.out.println (
// line n1
);
Which code fragment, when inserted at line n1, enables the code to print the count of string elements whose length is greater than three?
Given the code fragment:
List
System.out.println (
// line n1
);
Which code fragment, when inserted at line n1, enables the code to print the count of string elements whose length is greater than three?
To count the number of string elements in the list where the length of each string is greater than three, you can use the stream API in Java. The filter method is used to include only elements that meet the specified condition, and the count method returns the number of elements in the stream. The correct code fragment is: listVal.stream().filter(x -> x.length()>3).count().
Answer is A
Answer is A.
A, tested
A is the correct answer
A is correct.
Correct answer is A.
Answer is A and output is 2: List<String> listVal = Arrays.asList("Joe", "Paul", "Alice", "Tom"); System.out.println ( listVal.stream().filter(x -> x.length()>3).count() );