Exam 1z0-819 All QuestionsBrowse all questions from this exam
Question 115

Given the content from the course.txt file:

Given the code fragment:

Which code fragment at line 1 prints the lines that contain Java from the course.txt file?

    Correct Answer: E

    To print the lines that contain 'Java' from the course.txt file, we need to read the file line by line and filter the lines that contain the word 'Java'. The best way to achieve this is to use the Files.lines method to create a stream of lines from the file, filter the lines that contain 'Java', and then print each of those lines. The correct code fragment is Files.lines(filePath).filter(s -> s.contains('Java')).forEach(System.out::println);. This approach is efficient and directly addresses the requirement.

Discussion
d7bb0b2Option: E

E is correct: A: readAllLines return a List<String> not Stream<String> //not compilee B: print true C: print true false true D: not compile because contains return true and is expected list<string> So E is correct answer readAllLines return a stream that is filter only lines "java" and print that elements 123:Java:1 124:Java Server Pages:3

StavokOption: E

E is Correct

KiraguJohnOption: E

E Files.lines(filePath).filter(s->s.contains("Java")).forEach(System.out::println);