I want to make function for typeconverter room. The original data is in List and i store it as String in database.
My code and the output is like this:
fun main() {
val genreIds = listOf(28, 80)
val stringFromList = fromList(genreIds)
val stringToList = toList(stringFromList)
println(genreIds) // output: [28, 80]
println(stringFromList) // output: [28, 80]
println(stringToList) // output: [91, 50, 56, 44, 32, 56, 48, 93]
}
fun fromList(genreIds: List<Int>): String = genreIds.toString()
fun toList(genreIdString: String): List<Int> {
return genreIdString.map { it.toInt() }
}
I did try to use split(",") but it always give me error because of the "[" and "]". I want the output of toList function is [28, 80] too. Thanks for help.