Kotlinlearncs.online LogoJava
Return to List

Solve: Count Valid Strings

Created By: Rohith Sanjay
/ Version: 2024.9.1

Write a method countValidStrings that accepts one argument: a List<String> called list. Each String in the list contains parts separated by colons (:). Your method should count and return (as an Int) the number of strings in the list where the value immediately after the first colon, after trimming whitespace, equals "valid" (case-insensitive).

For example, "CS124: valid" is counted because the part after the first colon is " valid", which after trimming equals "valid". "CS124: VALID" is also counted because the comparison is case-insensitive. "CS124: invalid" is not counted because "invalid" is not equal to "valid".

Note that only the part immediately after the first colon matters. For example, "aa: bb: valid" is not counted because the part after the first colon is " bb", not "valid". However, "aa: valid: bb" is counted because the part after the first colon is " valid".

As usual, lists are built-in to Kotlin and available for you to use to solve this problem.

Related Lessons

Stuck? You may find these lessons helpful:

Report a Problem

Attribution must link to this page: https://www.learncs.online/solve/kotlin/count-valid-strings/[email protected]