zoukankan      html  css  js  c++  java
  • Java8 集合相关操作

    // java8 集合快速转成string
    List<String> cities;
    String citiesCommaSeparated = String.join(",", cities);
    
    // 集合去掉null元素
    new ArrayList<>().removeIf(Objects::isNull);
    
    // String 以-隔开,转成List
    List<String> list = Arrays.asList(string.split("-")).stream().
    map(s -> s.trim()).collect(Collectors.toList());
    
    // "1","2","3" 转换成 List<Long>
    List<Long> list = Arrays.asList(str.split(",")).stream().
            map(s -> Long.parseLong(str.trim())).collect(Collectors.toList());
            
    // String,隔开,转成数组
    Integer[] venderIds = Arrays.asList("1,2,3".split(Separator.COMMA))
    .stream().map(s -> Integer.parseInt(s)).toArray(Integer[]::new);
    
    // String数组  String[] venderIds转换成Integer数组
    Arrays.stream(venderIds).map(Integer::valueOf).toArray(Integer[]::new)
    
    // 集合过滤 收集importDataRecordBo对象集合中异常的行号
    List<Integer> errRowNums = importDataRecordBos.stream().filter(item -> !item.isSuccess())
            .map(ImportDataRecordBo :: getRowNum).collect(Collectors.toList());
    
    // 如何边遍历边移除 Collection 中的元素?
    Iterator<Integer> it = list.iterator();
    while(it.hasNext()){
        // do something
        it.remove();
    }
    
    // 删除ArrayList中重复的元素
    Set<Integer> set = new HashSet<Integer>(list);
    list.clear();
    list.addAll(set);
    
    
    
  • 相关阅读:
    vue中富文本编辑框
    vue中生成二维码
    在ABP中使用linq
    js根据年月得到当前这个月总共有多少天
    mescroll在vue中的应用
    javascript积累
    javascript常用的操作
    情侣间常犯的7个沟通问题
    欧洲旅游六大最佳目的地
    见与不见
  • 原文地址:https://www.cnblogs.com/ngrzr/p/11982991.html
Copyright © 2011-2022 走看看