key:3-keykey:/v1.02-keyException 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"; Mapsource = new HashMap<>(); source.put("1-key", "1-value"); source.put(StartFlag + "2-key", "2-value"); source.put("3-key", "3-value"); Iterator > iterator = source.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry 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());