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());
  • 相关阅读:
    拜师鸟哥之linux学习体会(1)——计算器概论
    LeetCode刷题1
    jupyter notebook直接打开.md格式的文件
    [图论]最短网络:prim
    [图论]最短网络:kruskal
    [图论]最优布线问题:kruskal
    A+B Problem
    [图论]最优布线问题:prim
    [图论]求连通分量
    [图论]连通图:深搜(邻接矩阵)
  • 原文地址:https://www.cnblogs.com/softidea/p/6255298.html
Copyright © 2011-2022 走看看