Kotlinlearncs.online LogoJava
Return to List

Solve: String Duplicate Words Ignore Case

Created By: Geoffrey Challen
/ Version: 2021.9.0

Given a String containing words separated by the " " (space) character, write a method hasDuplicateWords that returns true if any word appears twice in the String. Also, you should ignore case: so "Chuchu" and "chuchu" are considered the same word. assert that the passed String is not null.

So, for example, given the String "Wow that is amazing", you would return false, but given the String "Chuchu chuchu xyz" you would return true.

Our intention is for you to solve this problem using a Set, but there are also solutions that use a Map. You should not use a nested loop to solve this problem. You may want to use the toLowerCase method of Java Strings.

Related Lessons

Stuck? You may find these lessons helpful: