我想将其转换为循环流线
List<String> newLore = new ArrayList<>();
for (String str : description) {
newLore.add(ChatColor.translateAlternateColorCodes('&', str));
}
itemMeta.setLore(newLore);
使用以下方法链。关键是将map
每个项目转移到一个新项目,最后收集到一个项目List
。
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);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句