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?
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?
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.
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
E is Correct
E Files.lines(filePath).filter(s->s.contains("Java")).forEach(System.out::println);