• Post Reply Bookmark Topic Watch Topic
  • New Topic

checking for keyword does not exist  RSS feed

 
Chris Kislow
Greenhorn
Posts: 21
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I trying to figure out what kind of 'if statement' or other statement to resolve this issue

I have 2 files 1 with keywords like ("Hello, goodbye") and a 2nd file that has all kinds of senetences in it.  I have figured out how to find each keyword from file1 in file2, but what if the keyword does nto exist how do I
write up code to check if the keyword is missing from file 2?  would it be something like

if keyword.matches
  print "found it"
else
get next line from file2
else
keyword does not exist

thanks
 
Junilu Lacar
Sheriff
Posts: 11476
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is just an extension of what you were advised to do in this thread: https://coderanch.com/t/673700/java/find-keyword-text-file

There, you needed to find which keywords listed in one file existed in the text that in the other file.  The solution was to get an intersection of the two sets of words in each file.

Now you're trying to figure out the opposite: which keywords are NOT in the text of the other file.  This is another set operation, where you subtract the set of keywords that do exist in the other file from the set of *all* keywords. That would leave you with the keywords that *don't* exist in the other file.

Are you required to use an if statement? Because just an if-statement won't cut it. You have to iterate through the set(s) of words.  The built-in set operations hide that iteration from you but if you have to do it yourself, then you'd need to add a loop of some kind.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!