假设我们有一个包含以下元素的Integer数组:
20, 50, 100, 200, 250, 300, 500, 550, 600, 700
将其转换为列表:
Arrays.asList(20, 50, 100, 200, 250, 300, 500, 550, 600, 700)
使用Map获得大于400的值并转换为String:
filter(val -> val > 400) .map(val -> "Value greater than 400 = " + String.valueOf(val))
以下是使用Map将整数转换为String的示例:
import java.util.Arrays; public class Demo { public static void main(String[] args) { Arrays.asList(20, 50, 100, 200, 250, 300, 500, 550, 600, 700) .stream() .filter(val -> val > 400) .map(val -> "Value greater than 400 = " + String.valueOf(val)) .forEach(val -> System.out.println(val)); } }
输出结果
Value greater than 400 = 500 Value greater than 400 = 550 Value greater than 400 = 600 Value greater than 400 = 700