Created
February 5, 2018 22:21
-
-
Save sorokod/818ccd65cad967cdecb7dbf4006e4fa0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import java.util.List; | |
import java.util.function.Function; | |
import java.util.stream.Stream; | |
import static java.nio.file.Files.lines; | |
import static java.nio.file.Paths.get; | |
import static java.util.stream.Collectors.toList; | |
public class FileLineByLine { | |
private static <T> List<T> file2T(String fileName, Function<String, T> transform) throws IOException { | |
try (Stream<String> stream = lines(get(fileName))) { | |
return stream | |
.map(line -> transform.apply(line)) | |
.collect(toList()); | |
} | |
} | |
public static void main(String args[]) throws Exception { | |
List<Double> doubles = file2T(args[0], Double::parseDouble); | |
System.out.println(doubles); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment