private static List<String> getNoRepeatFileNameList(List<String> fileNameList) { Map<String, List<String>> fileNameMap = fileNameList.stream().collect(Collectors.groupingBy(x -> x)); List<String> newFileNameList = new ArrayList<>(); for (Map.Entry<String, List<String>> entry : fileNameMap.entrySet()) { String key = entry.getKey(); List<String> value = entry.getValue(); if (value.size() > 1) { int index = 1; for (String name : value) { String newName = String.format("%s(%s)%s", name.substring(0, name.lastIndexOf(".")), (index++), name.substring(name.lastIndexOf("."))); newFileNameList.add(newName); } } else { newFileNameList.add(key); } } return newFileNameList; }
标签:重命名,一堆,name,文件名,List,newFileNameList,value,entry,String From: https://www.cnblogs.com/hdwang/p/17236596.html