Scala

Scala

Made by DeepSource

Consider using the appropriate overloaded method when searching for a single char SC-P1004

Performance
Major

Methods such as String.indexOf and String.lastIndexOf allow you to search for an occurrence of either a single char or a substring within a String. If you'd like to search for an occurrence of a single char, it is recommended that you use the appropriate method that takes a Char as a parameter rather than a String as the former approach is more performant and recommended.

Bad practice

val lang = "Scala"

// Searching for `a` using the method that takes a String as a parameter.
// Although this works, it is not an efficient approach.
val idx  = lang.indexOf("a")

Recommended

val lang = "Scala"

// Searching for `a` using the method that takes a Char as a parameter.
// This is the recommended performant approach.
val idx  = lang.indexOf('a')