how to convert list<string, list<string>&...
# android
m
how to convert list<string, list<string>> to string
😶 4
l
list.toString() or list.joinToString() if you want it separated by commas
m
List cannot have two generics. Is that supposed to be
List<Pair<String, List<String>>
and if so what is the desired output?
m
The desired output is a string with all elements by means of a line break.
c
list.joinToString("\n")
m
nope With this I am getting
Copy code
Country1, [city1, city2, city3]
Country2, [city4, city5]
but I want
Copy code
"Country1
city1,
city2,
city3
Country2,
city4,
city5"
c
list.map { "${it.first},${it.second.joinToString("\n")}" }
list.map { "${it.first},${it.second.joinToString(",")}\n" }
✅ 1
second one puts everything on one line as CSV with a newline, if that is the desired output.
m
thanks!
m
list.joinToString(separator = ",\n") { "$it.first,\n${it.second.joinToString(separator = ",\n")}") }