Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ch.claude_martin;
- import java.io.IOException;
- import java.nio.file.Files;
- import java.nio.file.Path;
- import java.nio.file.Paths;
- import java.util.Optional;
- public class SomeClass {
- public static void main(String... args) {
- var filename = args[0];
- var city= args[1];
- Path path = Paths.get(filename);
- try (var lines = Files.lines(path)) {
- Optional<String> first = lines.filter(s -> s.contains(city)).findFirst();
- System.out.println(first.orElse("City not found"));
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement