gpt4 book ai didi

java - 合并 3 或 4 个流并在其中一些中进行编辑

转载 作者:行者123 更新时间:2023-11-30 06:15:44 25 4
gpt4 key购买 nike

又是我。我们必须编写一个摩尔斯电码转换器,我想我了解这个理论,并且我还使用创建了我的 HashMap 。我想尝试使用流,你们中有人知道我如何组合流以及如何编辑它们吗?因为我想这样做

read file by lines

split in words

split words in chars

compare char with the key of the map and add the value to a String

我绝对不想要整个代码,因为我想自己完成大部分代码,但有人可以向我解释一下吗

1st stream + split in the next stream This would be very helpful for me.

问候,卢卡斯。

最佳答案

如你所愿:将文件作为行流读取:

try (Stream<String> stream = Files.lines(Paths.get("file-path"))) {
...
} catch ...

现在你有了行流 - 你需要将它们分成单词:诸如: line -> line.split("\\W+"); 将为每个流成员(行)等执行...

关于java - 合并 3 或 4 个流并在其中一些中进行编辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49241209/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com