디렉토리에있는 파일의 중복을 찾으려고합니다.JAVA HashMap duplicate
public void findFiles(ArrayList<File> list){
HashMap<String, File> hmap = new HashMap<String, File>();
hmap.put(list.get(0).getName(), list.get(0));
//System.out.println(hmap);
for(Entry<String, File> entry : hmap.entrySet()){
String key = entry.getKey();
File value = entry.getValue();
// i don't understand what I need to write below
if (hmap.containsKey(key))
{
System.out.println("Duplicate: " + key + " in "+ value.getAbsolutePath());
}
}
}
어떻게 내 if 문을 다시 작성해야합니다
내가 인수로 파일의 주소가이 블록상의 문제가?System.out.println(hmap);
그리고 다음 examlpes 있습니다
{File 2.txt=D:\Folder1\Folder1-2\Folder1-2-1\File 2.txt}
{DFolder1.txt=D:\Folder1\Folder1-2\Folder1-3-1\DFolder1.txt}
{File 1.txt=D:\Folder1\Folder1-2\File 1.txt}
{File 1.txt=D:\Folder1\Folder1-3\File 1.txt, File 3.txt=D:\Folder1\Folder1-3\File 3.txt}
{File 3.txt=D:\Folder1\File 3.txt}
나는이 두 "파일 1.TXT"
가능한 중복 [HashMap의 중복을 허용?] (http://stackoverflow.com/questions/20537898/hashmap-allows-duplicates) – Xstian
는이 디렉토리에 중복 파일을 만들 수 있습니까? – EvenPrime