-7

The below code works fine in Java 8.

files.addAll(Arrays.asList(folder.listFiles((f) -> f.getName()
                .endsWith(CustomConstantsRepository.FILE_EXT_DAT)
                && f.getName().startsWith(fileName))));

I need the same functionality to work in Java 7.

Thanks in advance.

1 Answers1

1

You would use an Anonymous Inner Class, as Java 8 lambda expressions are essentially syntatical sugar which do nearly the same thing. That would look something like this.

files.addAll(Arrays.asList(folder.listFiles(new FileFilter(){

        @Override
        public boolean accept(File f) {
            return f.getName().endsWith(CustomConstantsRepository.FILE_EXT_DAT) && f.getName().startsWith(fileName)));
        }

})));
d_scalzi
  • 425
  • 4
  • 13