当前位置: 首页 > news >正文

java常用数据转换

1.   List与数组互转
    ArrayList<String> list = new ArrayList<>();
    String[] array = list.stream().toArray(String[]::new);


    String[] array1 = {"apple", "banana", "orange"};
    List<String> list1 = Arrays.stream(array1).collect(Collectors.toList());

    String[] cateArray = cateList.toArray(new String[cateList.size()]);

2.new集合对像
    import com.google.common.collect.Lists;
    import com.google.common.collect.Maps;
    List<String> arrayList = Lists.newArrayList();
    Map<String, Object[]> concurrentMap = Maps.newConcurrentMap();
    Map<String, Object> resultMap = Maps.newHashMap();

3.集合转字符串

   例1:List<String> attachListFar = new ArrayList<>();
       attachListFar.add(attachDto.getFilePath());
    String attachListFarStr = String.join(",", attachListFar);

例2:if (StringUtils.isNotBlank(approvedBy)) {
    StringJoiner userStrJoin = new StringJoiner(",");
    String[] userIds = approvedBy.split(",");
    for (String uId : userIds) {
        String com = RedisUtil.getName(RedisConstant.SYS_DEPT_USER_ID, uId);
        userStrJoin.add(com);
    }
    outDto.setApprovedByName(userStrJoin.toString());//多人名字
}

    4.stream集合变换:
    //list对象
    List<String> idList= todoViewList.stream().map(HdInfoTodoView::getId).collect(Collectors.toList());
    dto.setHdIds(listWithoutRepeat.toArray(new String[listWithoutRepeat.size()]));
    Map<String, List<SafetyInspectRecordDetail>> map = list.stream().collect(Collectors.groupingBy(SafetyInspectRecordDetail::getInspectRecordId));
   //map对象
Map<String, String> levelMap = inspectLevelResult.getData() == null ? Maps.newConcurrentMap() : inspectLevelResult.getData().stream().collect(Collectors.toMap(SysDictDataOutDto::getDictValue, SysDictDataOutDto::getDictLabel, (k, v) -> v));
    
    //map对象
    Map<String, HdInfoOutDto> hdMap = list.stream().collect(Collectors.toMap(HdInfoOutDto::getId, p -> p, (k, v) -> v));
                
    // 去重
     List<String> userNameList = list.stream().filter(c -> MyStringUtil.isNotEmpty(c.getUserName())).map(CisAlarm::getUserName).distinct().collect(Collectors.toList());
     
    

相关文章:

  • 软件设计师笔记持续更新-看学以致知视频笔记
  • 中微单片机学习--SC8F072
  • 【蓝桥杯速成】| 8.回溯算法
  • C语言 第五章 指针(3)
  • 实用工具-Another Redis Desktop Manager介绍
  • electron桌面应用多种快速创建方法
  • 如何通过Odoo 18创建与配置服务器操作
  • 楼宇自控系统的结构密码:总线与分布式结构方式的差异与应用
  • Jackson 库进行 JSON 序列化时遇到了 ‌无限递归(Infinite Recursion)‌ 问题
  • 嵌入式笔记 | 正点原子STM32F103ZET6 5 | 串口通信
  • kafka的文章
  • C#从入门到精通(1)
  • 路由Vue Router基本用法
  • QEMU 中 x86_cpu_realizefn 到 ept_emulation_fault 的调用流程解析(macos)
  • 数据库的两种模式
  • 国内首家,百度智能云千帆AppBuilder全面兼容MCP协议
  • dfs(二十一)46. 全排列 中等
  • 【Linux】信号:产生信号
  • 夜莺监控 v8.0 新版通知规则 | 对接飞书告警
  • 【数据分析】数据筛选与访问行列元素3
  • 唐山哪家做网站好/怎么让某个关键词排名上去
  • 网页游戏网站模板/广告优化师怎么学
  • 政府网站建设思路汇报/百度app下载安装官方免费下载
  • 百川互联/seo外链工具
  • 网站关键词库是怎么做的/怎么建个网站
  • 微信网站在线登录网页版/百度小说排行榜风云榜单