Replace non-string literal

Report a typo

We are writing a function that takes a list of objects of type Any and returns a list of strings obtained by reducing each object of the list to the type String using the as operator. If the type cannot be cast, the function must replace the corresponding list item with the string "N/A".

For example, for the input: ["hello", "world", 3, true], we should get the output: ["hello", "world", "N/A", "N/A"]

Write a program in Kotlin
fun convertToStringList(list: List<Any>): List<String> {
val stringList = mutableListOf<String>()
for (element in list) {
val stringElement = // make your code here
stringList.add(stringElement)
}
return stringList
}
___

Create a free account to access the full topic