This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I want to check which words that i read from an input text file (one word per line) do not exist in an array of strings (that I already have in my program). I used the .equals to compare the word to every word of my array. Then when I ask the program to print, when a word does not occur in the array I see e.g. 10 times (=number of elements in the array) the phrase ("The word" + fileLine+ "does not occur."). What should I do? When using array there is no 'boolean cointains ();' [ November 22, 2007: Message edited by: Crescento Anho ]
I guess you could write a method which returns a boolean... The first thing that comes to mind would be
// create method that takes two parameters: the fileLine, and the array // set a boolean flag to false // go through the whole array // if you encounter the word, set the flag to true // return the flag
There are probably dozens of good ways to do it (and maybe even something in the API).