How to filter strings from one stream which are not contained in another sream?

Trillian :

I have two streams of Strings like :

Stream<String> thisWeekFile = Files.lines(thisWeekPath);
Stream<String> lastWeekFile = Files.lines(lastWeekPath);

In comparison to last week this weeks file can have the same strings, some strings added or some strings removed. For now I'm only interested in the strings which were present in last weeks file but not any more in this weeks file. How do i get those strings? I tried

lastWeekFile.filter(e->!thisWeekFile.anyMatch(e)); 

The above giving an error :String can not be converted to predicate.

Idealy i want something like

lastWeekFile.filter(e->!thisWeekFile.contains(e));
Ruslan :

Using Files.readLines() method that returns List instead of stream it can be done without stream api:

List<String> thisWeekFile = Files.readAllLines(thisWeekPath);
List<String> lastWeekFile = Files.readAllLines(lastWeekPath);

lastWeekFile.removeAll(thisWeekFile);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=89878&siteId=1