I have been reviewing the following question but I'm still a bit confused. How may I loop through files, looping through the contents of each file, adding only the distinct values from ALL the files to one List? Should I use a set?
getSourceFiles
returns a LinkedHashMap of Paths which I then cast to File objects
public static void main(String[] args) throws IOException {
mapSwift = getSourceFiles(PATH_SWIFT, swiftFileName);
linkedHashSet = new LinkedHashSet();
mapSwift.forEach((k,v)-> {
File fileName = new File(v.toString());
try (Stream<String> stream = Files.lines(Paths.get(String.valueOf(fileName)))) {
list = stream
.filter(line -> line.startsWith(":97A::SAFE//"))
.map(String::toUpperCase)
.distinct()
.collect(Collectors.toList());
} catch (IOException e) {
e.printStackTrace();
}
linkedHashSet.add(list);
});
System.out.println("Done");
}
//public static LinkedHashMap<?, ?> getSourceFiles(Path dir, String strFilename)
Expected Output
File A | File B | File C
Oranges Apples Bananas
Apples Apples Oranges
I would like the resulting Array or Set to have only unique vales from ALL files. With the above example, the ending data structure would only contain 3 elements, Oranges, Apples, Bananas