且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何为字符串数组中的每个元素添加字符串前缀?

更新时间:2022-04-03 09:41:21

不.由于它应该是一个三行函数,因此您***坚持使用您编写的代码.

Nope. Since it should be about a three-line function, you're probably better of just sticking with the one you coded.

Java 8 的语法非常简单,我什至不确定是否值得为以下对象创建函数:

With Java 8, the syntax is simple enough I'm not even sure if it's worth creating a function for:

List<String> eatFoods = foodNames.stream()
    .map(s -> "eat an " + s)
    .collect(Collectors.toList());