[Solved] Stream filter regex [closed]

[ad_1]

You can use String's startsWith method for this:

List<File> fileListToProcess = Arrays.stream(allFolderPath)
                .filter(myFile -> myFile.getName().startsWith("archive_"))
                .collect(Collectors.toList());

OR
You can use following regex to check if your string starts with archive_:

^(archive_).*

like:

List<File> fileListToProcess = Arrays.stream(allFolderPath)
                    .filter(myFile -> myFile.getName().matches("^(archive_).*"))
                    .collect(Collectors.toList());

[ad_2]

solved Stream filter regex [closed]