我正在java 8中练习流,我试图制作一个Stream<Integer>包含2的倍数.在一个主类中有几个任务所以我不会链接整个块但是到目前为止我得到的是:
Integer twoToTheZeroth = 1;
UnaryOperator<Integer> doubler = (Integer x) -> 2 * x;
Stream<Integer> result = ?;
Run Code Online (Sandbox Code Playgroud)
我的问题可能与流不相关,更像是语法,我应该如何使用doubler来获得结果?
提前致谢!
所以,我需要逐行读取文本文件,并按字符串返回它们.我可以指定从哪行到哪一行我想读它.
我的班有3种方法:
public class FilePartReader {
String filePath;
Integer fromLine;
Integer toLine;
public FilePartReader() { }
public void setup(String filepath, Integer fromLine, Integer toLine) {
if (fromLine < 0 || toLine <= fromLine) {
throw new IllegalArgumentException(
"fromline cant be smaller than 0 and toline cant be smaller than fromline");
}
this.filePath = filepath;
this.fromLine = fromLine;
this.toLine = toLine;
}
public String read() throws IOException {
String data;
data = new String(Files.readAllBytes(Paths.get(filePath)));
return data;
}
public String readLines() { …Run Code Online (Sandbox Code Playgroud)