public static void main(String[] args) throws IllegalAccessException { //字符串转换为数字且每个加上100,输出。 String[] ids = {"100","12","23","45","68","78","99","200"}; List<Integer> list = Stream.of(ids).map(x -> Integer.valueOf(x) 100).collect(Collectors.toList()); //编译循环 list.stream().forEach(x -> System.out.print(x ",")); //按1.8编译 Integer[] array = { 1, 2, 3, 4, 5 }; Stream.of(array).forEach(System.out::println); // prints 1, 2, 3, ... // Arrays.stream(array).forEach(System.out::println); //Mysql in 查询参数 String str = Stream.of(array).map(x -> "'" String.valueOf(x) "'").collect(Collectors.joining(",","(",")")); System.out.println("str=" str); //求和 // Integer sum = Stream.of(array).mapToInt(x -> x).sum(); // Integer sum = Stream.of(array).mapToInt(Integer::valueOf).sum(); Integer sum = Stream.of(array).mapToInt(x -> Integer.valueOf(x)).sum(); System.out.println("sum=" sum); }
字符数组转换及数字求和 java8 lambda表达式 demo
2024-10-09 08:00:50
浏览数 (1)