I'm trying to find the duplicates of files in the directory.
I have a problem with this block, that has file's address as an argument:
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());
}
}
}
How should I rewrite my if statement?
System.out.println(hmap);
And have next 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}
I have two "File 1.txt"