I aimed to rework the code found here: https://stackoverflow.com/a/8995988 But this proved unsuccessful. I got an idea from here: https://www.logicbig.com/how-to/java/lambda-list-contains-a-substring.html
And my idea worked, but I suspect it is bad code and I'd like to know why the StackOverflow rework I did does not work as anticipated.
I'll present both bits of code in 1 block. Simply switch which "if" line is commented and not commented to go between the working and not working versions.
import java.util.Arrays;
import java.util.List;
public class Demo {
public static void main(String[] args) {
List<String> result0 = Arrays.asList("/Videos/Templates/file.mp4", "/Videos/Templates/file2.mp4", "/Videos/Templates/file3.mp4");
List<String> result2 = Arrays.asList("/Videos/Templates/file.mp4.sha256");
for (int i = 0; i < result0.size(); i++) {
List<String> finalResult = result0;
int finalI = i;
// if (result2.parallelStream().anyMatch(x -> x.contains(finalResult.get(finalI)))) {
if (result2.parallelStream().anyMatch(finalResult.get(finalI)::contains)){
System.out.println("sha matches files: " + result0.get(i));
}
}
}
}
If it proves that this question better serves as just a comment on https://stackoverflow.com/a/8995988 better explaining the code, then I'm happy to modify to that.