I am working java project. I am trying to filter a specific csv file if the the given string matches. Currently ,I am able to filter the rows from csv file but I want filter function to return the matched string rows rather than giving me rows which are not a match. how to achieve this ?
Here is the code i have so far:
File file = new File(original_file_format);
//data to be searched
final String finString = "Humans";
List<String> lines = FileUtils.readLines(file);
List<String> updatedLines = lines.stream()
.map(s-> s.trim())
//currently i am getting output rows without "Humans" in it, but i want the rows which has "Humans" in it as output
.filter(s -> !s.matches(finString.trim()) ).collect(Collectors.toList());
FileUtils.writeLines(file, updatedLines, false);