天王盖地虎,我怕米老鼠 2018-10-09 08:57 采纳率: 66.7%
浏览 450
已采纳

如图,用java处理,想获取以下数据形式该怎么写

图片说明

 两表关联,如A表字段1第一行所示,整个字段1想获取那样形式,用Java该怎么处理,用map集合方式带入去获取,获取的数据总是不完全,求指教
  • 写回答

1条回答 默认 最新

  • 诚哥丿 2018-10-09 09:24
    关注
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import java.util.Map.Entry;
    
    import org.apache.commons.lang3.StringUtils;
    import org.junit.Test;
    
    public class MapTestCase {
    
        @Test
        public void test(){
    
        //A 表字段2
        String[] array = {"张三,王五", "李四,王五", "张三,李四"};
    
        //B 表
        Map<String, String> dictMap = new HashMap<>(3);
        dictMap.put("A", "张三");
        dictMap.put("B", "李四");
        dictMap.put("C", "王五");
    
        //A表
        Map<String, String> resultMap = new HashMap<>(3);
    
        for (int i = 0; i < array.length; i++) {
            List<String> list = new ArrayList<>(2);
            String[] arr = array[i].split("\\,");
            for (int j = 0; j < arr.length; j++) {
                String name = arr[j];
                for (Entry<String, String> entry : dictMap.entrySet()) {
                    if(name.equals(entry.getValue())){
                        list.add(entry.getKey());
                    }
                }
            }
            String newKey = StringUtils.join(list, ",");
            resultMap.put(newKey, array[i]);
        }
    
        System.out.println(resultMap.toString());
    }
    
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 (关键词-电路设计)
  • ¥15 如何解决MIPS计算是否溢出
  • ¥15 vue中我代理了iframe,iframe却走的是路由,没有显示该显示的网站,这个该如何处理
  • ¥15 操作系统相关算法中while();的含义
  • ¥15 CNVcaller安装后无法找到文件
  • ¥15 visual studio2022中文乱码无法解决
  • ¥15 关于华为5g模块mh5000-31接线问题
  • ¥15 keil L6007U报错
  • ¥15 webapi 发布到iis后无法访问
  • ¥15 初学者如何快速上手学习stm32?