Checking for an item in a list is quite slow, because you have to search one-by-one through the list. Finding something in a
Java Set, though, is quite fast: TreeSet and especially HashSet lookups take very little time even for huge sets. Read your list of file names and put them into a HashSet, and then check whether the HashSet contains each name --
you should find this to be enormously faster.