首页 > 其他分享 >对相同的key中的value进行合并

对相同的key中的value进行合并

时间:2024-06-04 17:00:10浏览次数:10  
标签:code ToolCode Dirver 对象 合并 value label key groupedMap

// 假设 ccmdbCarWeizis 是一个包含 CarWeizi 对象的列表
ccmdbCarWeizis.forEach(carWeizi -> {
    // 提取 CarWeizi 对象的 carInformation 属性的前三个字符作为省份简称
    String label = carWeizi.getCarInformation().substring(0, 3);
    // 检查 groupedMap 是否已经包含这个省份简称作为键
    if (!groupedMap.containsKey(label)) {
        // 如果不包含,将这个简称作为键,并将一个新的空 ArrayList<Dirver> 作为值添加到 groupedMap 中
        groupedMap.put(label, new ArrayList<>());
    }
    // 获取 groupedMap 中与省份简称关联的 Dirver 对象列表
    List<Dirver> existingList = groupedMap.get(label);
    // 创建一个新的 Dirver 对象,其 id 为 1,label 为 carWeizi 的 carCodeNumber
    existingList.add(new Dirver(1, carWeizi.getCarCodeNumber()));
});

// 初始化一个用于存储 ToolCode 对象的列表
List<ToolCode> arrayList = new ArrayList<>();
// 遍历 groupedMap 的所有条目
for (Map.Entry<String, List<Dirver>> entry : groupedMap.entrySet()) {
    // 对于每个条目,创建一个新的 ToolCode 对象
    ToolCode code = new ToolCode();
    // 设置 ToolCode 对象的 children 属性为当前条目的值(即对应省份的 Dirver 列表)
    code.setChildren(entry.getValue());
    // 设置 ToolCode 对象的 id 属性为 1
    code.setId(1);
    // 设置 ToolCode 对象的 label 属性为当前条目的键(即省份简称)
    code.setLabel(entry.getKey());
    // 将新创建的 ToolCode 对象添加到 arrayList 中
    arrayList.add(code);
}

 

标签:code,ToolCode,Dirver,对象,合并,value,label,key,groupedMap
From: https://www.cnblogs.com/188221creat/p/18231245

相关文章

  • 字符串的应用---合并
    准备:publicclassEmployee{publicintId{get;set;}publicstringName{get;set;}publicdoubleSalary{get;set;}}publicclassSeat{publicintId{get;set;}publ......
  • 详解和实现数据表格中的行数据合并功能
    theme:smartblue前言需求场景:在提供了数据查看和修改的表格视图中(如table、a-table等…),允许用户自行选择多行数据,依据当前状态进行特定列数据的合并操作。选中的数据将统一显示为选中组的首条数据值。同时,页面会即时反馈显示合并后的效果,提供直观的操作反馈。效果......
  • error:connot bind non-const lvalue reference of type ‘std::__cxx11::string& {ak
    实习记录犯错日志:std::stringutf8_str=gbk_to_utf8((char*)struCIDAlarmInfo.sCIDCode);代码这样写则报如题所示的错误,error:connotbindnon-constlvaluereferenceoftype'std::__cxx11::string&{akastd::cxx11::basic_string<char>&}toanrvalueoftype'......
  • 在MySQL中,你可以使用动态SQL和存储过程来根据元数据表查询多个表,并将结果集合并。以下
    DELIMITER$$CREATEPROCEDUREMergeDataFromTables()BEGIN--游标声明DECLAREdoneINTDEFAULTFALSE;DECLAREtbl_nameVARCHAR(255);DECLAREcurCURSORFORSELECT表明FROMtable_col;DECLARECONTINUEHANDLERFORNOTFOUNDSETdone=TRU......
  • jacoco覆盖率多版本exec合并
    @目录概要概要所有代码已经上传到gitee,仓库地址:https://gitee.com/chen_zai_xing/jacoco。方法指令合并参考ray大佬的https://blog.csdn.net/tushuping/article/details/131640959?spm=1001.2014.3001.5502,大佬在文中未提及指令签名带上指令相对于方法中的序号,这里补充说明下。......
  • iview table 表头单元格合并
    <Tableborder:columns="cusColumns":data="cusData"></Table>cusColumns:[{title:'门店/节点',align:'center',//fixed:'left',minWidth:100,render:(h,para......
  • 【Git 版本管理】合并 + 变更,看懂Git
    看懂Git合并操作分离HEAD分离HEAD测试相对引用(^||~)操作符^相对引用^测试操作符~相对引用~测试撤销变更GitResetGitRevert撤销变更测试整理提交记录GitCherry-pick测试交互式rebase交互式rebase测试合并操作关键字:commit、branch、merge、......
  • 代码随想录算法训练营第二十天 | 654.最大二叉树 617.合并二叉树 二叉搜索树
    654.最大二叉树题目链接文章讲解视频讲解classSolution{public:TreeNode*constructMaximumBinaryTree(vector<int>&nums){returninorderTraversal(nums,0,nums.size()-1);}TreeNode*inorderTraversal(vector<int>&nums,intbegi......
  • canvas 合并图片和文字
    代码asyncgetImgInfo(img,text){returnnewPromise((resolve,reject)=>{constcanvas=document.createElement("canvas");canvas.width=52;canvas.height=68;constctx=canvas.getContext("2d");......
  • [题解]UVA11235 Frequent values
    https://www.luogu.com.cn/problem/UVA11235没看到多测调了半天每组数据给定\(n,q\)。接下来给出一个长度为\(n\)的不降序列\(A\)。接下来\(q\)次询问,每次询问给定\(l,r\),求\(A_{l\simr}\)中出现最多的那个数出现了多少次。\(1\len,q\le10^5\)。序列不降,意味着一个数在序......