The use of MultiValueMap (MultiValueMap where one key of Map stores multiple Values (one key with multiple values))!!

To be honest, when I first saw it, I was a little confused about what this is. Why I have never seen it before, I went to check the missing information with curiosity!!!

For detailed analysis, please refer to::https://blog.csdn.net/yanzhenjie1003/article/details/51550264

MultiValueMap can make a key correspond to multiple values. It feels that the value has a linked list structure, which can solve some difficult string problems. Of course, you can also use stringBuffer to spell, I think this effect is better and more efficient.

MultiValueMap<String, String> stringMultiValueMap = new LinkedMultiValueMap<>();

        stringMultiValueMap.add("早班 9:00-11:00", "周一");
        stringMultiValueMap.add("早班 9:00-11:00", "周二");
        stringMultiValueMap.add("中班 13:00-16:00", "周三");
        stringMultiValueMap.add("早班 9:00-11:00", "周四");
        stringMultiValueMap.add("测试1天2次 09:00 - 12:00", "周五");
        stringMultiValueMap.add("测试1天2次 09:00 - 12:00", "周六");
        stringMultiValueMap.add("中班 13:00-16:00", "周日");
         //打印所有值
        Set<String> keySet = stringMultiValueMap.keySet();
        for (String key : keySet) {
            List<String> values = stringMultiValueMap.get(key);
            System.out.println(StringUtils.join(values.toArray()," ")+":"+key);

        }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

output:

周一 周二 周四:早班 9:00-11:00
周三 周日:中班 13:00-16:00
周五 周六:测试1天2次 09:00 - 12:00

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325735076&siteId=291194637