android - ArrayList<File> contains filename -
i have problem arraylist (file in above code). arraylist composed files located sd. problem can have duplicates (the same image, in different paths sd, same filename different path) , want remove them. utilize code:
arraylist<file> removedduplicates = new arraylist<file>(); (int = 0; < file.size(); i++) { if (!removedduplicates.contains(file.get(i))) { removedduplicates.add(file.get(i)); } } but doesn't work, guess because contains() list of file looks @ filepath instead of @ filename. true? how can solve problem? tried with:
arraylist<file> removedduplicates = new arraylist<file>(); (int = 0; < file.size(); i++) { if (!removedduplicates.contains(file.get(i).getname())) { removedduplicates.add(file.get(i)); } } but still doesn't work. thanks
the type of getname string , type of object in arraylist file, you're never going same thing.
you want compare names within arraylist.
for(file f : files){ string fname = f.getname(); boolean found = false; for(file f2 : removedduplicates){ if(f2.getname().equals(fname)){ found = true; break; } } if(!found){ removedduplicates.add(f); } } android arraylist contains
No comments:
Post a Comment