Collection<File> (File[] candidates) { if (candidates == null || candidates.length == 0) { return Collections.emptyList(); } final Collection<File> result = new SmartList<>(); final String[] suffixes = new String[GEN_SUFFIXES.length]; for (int i = 0; i < GEN_SUFFIXES.length; i++) { suffixes[i] = baseName + GEN_SUFFIXES[i]; } for (File candidate : candidates) { final String name = candidate.getName(); for (String suffix : suffixes) { if (name.endsWith(suffix)) { result.add(candidate); break; } } } return result; }