Java Java Basics Perfecting the Prototype Censoring Words - Using Logical ORs

Simplifying the Logic

When Craig uses or's to censor out dork and jerk, instead of writing

noun.equalsIgnoreCase("dork") || noun.equalsIgnoreCase("jerk")

in his if statement, could he write

noun.equalsIgnoreCase("dork" || "jerk")

and on and on and on if we have more things to censor? I just feel like rewriting the entire variable and method is kind of bulky if we have more things we'd like to check for.

2 Answers

when we have more strings to censor may be we could add all the strings into a different data structure like a vector<Strings> and loop thru to find out if the particular string has to be censored.

Josip Dorvak
Josip Dorvak
18,123 Points

That would not work since ("dork" || "jerk") isnt a String but a Boolean (which is a true or false value). Later on he'll probably get to loops and arrays. The preferred way is to have an array of words (an array is a variable that can hold many variables) and loop through all Strings in the array and compare the noun to those.