小编Min*_*mut的帖子

java 8制作两个倍数的流

我正在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来获得结果?

提前致谢!

java math java-8 java-stream

3
推荐指数
1
解决办法
222
查看次数

如何从java 8中的文本文件中读取特定行?

所以,我需要逐行读取文本文件,并按字符串返回它们.我可以指定从哪行到哪一行我想读它.

我的班有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)

java text-files filereader

1
推荐指数
1
解决办法
344
查看次数

标签 统计

java ×2

filereader ×1

java-8 ×1

java-stream ×1

math ×1

text-files ×1