zoukankan      html  css  js  c++  java
  • 字符数组转换及数字求和 java8 lambda表达式 demo

    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);

    }

  • 相关阅读:
    firefox 插件开发2
    android ndk
    android Fragment.
    排序算法
    php中判断iphone版本
    php css
    ndk 入门实例
    howtoaddabuttontopreferencescreen 自定义view
    分布式K/V存储方案
    android版 eclipse
  • 原文地址:https://www.cnblogs.com/oktokeep/p/13228260.html
Copyright © 2011-2022 走看看