import java.io.*;
import java.util.*;
public class ComparingStrings {
static String[] words = {
"green", "blue", "cyan", "magenta", "orange", "black"
};
public static void main(String[] args) {
String path = "wordsToRead.txt";
StringBuilder sb = new StringBuilder();
try {
Scanner scanner = new Scanner(new File(path));
while(scanner.hasNextLine()) {
sb.append(scanner.nextLine() + " ");
}
scanner.close();
} catch(FileNotFoundException e) {
System.out.println("File not found " + e.getMessage());
}
String[] fileWords = sb.toString().split("\\s");
String[] extraWords = getNewWords(fileWords);
System.out.printf("extra words = %s%n", Arrays.toString(extraWords));
}
private static String[] getNewWords(String[] allWords) {
List<String> newWords = new ArrayList<String>();
for(int j = 0; j < allWords.length; j++) {
if(!isInWords(allWords[j]) && !newWords.contains(allWords[j]))
newWords.add(allWords[j]);
}
return newWords.toArray(new String[newWords.size()]);
}
private static boolean isInWords(String s) {
for(int j = 0; j < words.length; j++) {
if(words[j].equals(s))
return true;
}
return false;
}
}