zoukankan      html  css  js  c++  java
  • java.util.ConcurrentModificationException --map

    key:3-key
    key:/v1.02-key
    Exception in thread "main" java.util.ConcurrentModificationException
    	at java.util.HashMap$HashIterator.nextNode(HashMap.java:1429)
    	at java.util.HashMap$EntryIterator.next(HashMap.java:1463)
    	at java.util.HashMap$EntryIterator.next(HashMap.java:1461)
        public static void main(String[] args) {
            final String StartFlag = "/v1.0";
    
            Map<String, String> source = new HashMap<>();
            source.put("1-key", "1-value");
            source.put(StartFlag + "2-key", "2-value");
            source.put("3-key", "3-value");
    
            Iterator<Map.Entry<String, String>> iterator = source.entrySet().iterator();
            while (iterator.hasNext()) {
                Map.Entry<String, String> next = iterator.next();
                String key = next.getKey();
                System.out.println("key:" + key);
                String value = next.getValue();
                if (key.startsWith(StartFlag)) {
                    key = key.substring(StartFlag.length());
                    iterator.remove();
                    source.put(key, value);
                }
            }
            System.out.println(source);
        }
            URL resource = getClass().getResource("/swagger/project.json");
            System.out.println("URL:" + resource.toString());
            URI uri = resource.toURI();
            System.out.println("uri:" + uri);
    
            Path path = Paths.get(uri);
            File file = path.toFile();
            System.out.println("exists:" + file.exists());
  • 相关阅读:
    读《猫城记》 | 人间失格
    如果这都算是佛系
    常规流(Normal flow)
    页面重绘(repaint)和回流(reflow)
    display:none和visiblity:hidden区别
    读《人类简史》 | 一本很值得读的书
    Mac shell笔记
    读《围城》
    珠海游记
    mouseout、mouseover和mouseleave、mouseenter区别
  • 原文地址:https://www.cnblogs.com/softidea/p/6255298.html
Copyright © 2011-2022 走看看