Fill in the blanks on the method has Duplicates, which returns true if a stringl
ID: 3772216 • Letter: F
Question
Fill in the blanks on the method has Duplicates, which returns true if a stringlist contains duplicate names. You can use the contains method, defined, defined below, which returns true if (and only if) the argument name is contained in the stringlist. //contains("c") of list ("a", "b","c", "d") returns true contains ("e") of list ("a", "b", "c" , "d") returns false public boolean contains (string name) { if (value.equals (name)) { if value.equals (name) { return true; } else if (next == null) { return false; } else { return next. contains (name); } } public boolean has Duplicates () { if (next== null) { return-; } else if (next.contains(-)) { return-; } else { return - ; } }Explanation / Answer
// contains ("c") of list ("a", "b", "c", "d") returns true
// contains ("e") of list ("a", "b", "c", "d") returns false
public boolean contains (String name) {
if (value.equals(name)) {
return true;
} else if (next == null) {
return false;
} else {
return next.contains(name);
}
}
public boolean hasDuplicates() {
if (next == null) {
return false;
} else if (next.contains(value)) {
return true;
} else {
return false;
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.