我想将其转换为流线
List<String> newLore = new ArrayList<>();
for (String str : description) {
newLore.add(ChatColor.translateAlternateColorCodes('&', str));
}
itemMeta.setLore(newLore);
最佳答案
使用以下方法链。关键是将每个项目映射
到一个新项目,并最终收集到列表
。
List<String> newLore = description.stream() // Stream<String> with old elements
.map(str -> ChatColor.translateAlternateColorCodes('&', str)) // Stream<String> with the new ones
.collect(Collectors.toList()); // List<String>
itemMeta.setLore(newLore);
关于java - 我如何将此代码转换为 java 8 流?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61510364/