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.
The moose likes Beginning Java and the fly likes repeated println Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "repeated println" Watch "repeated println" New topic

repeated println

Crescento Anho

Joined: Nov 20, 2007
Posts: 4
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 ]
Katrina Owen

Joined: Nov 03, 2006
Posts: 1367
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).
I agree. Here's the link:
subject: repeated println
It's not a secret anymore!