Similar to @Rhusfer answer I wrote this. In case you have a group of EditText
s and want to concatenate their values, you can write:
listOf(edit_1, edit_2, edit_3, edit_4).joinToString(separator = "") { it.text.toString() }
If you want to concatenate Map
, use this:
map.entries.joinToString(separator = ", ")
To concatenate Bundle
, use
bundle.keySet().joinToString(", ") { key -> "$key=${bundle[key]}" }
It sorts keys in alphabetical order.
Example:
val map: MutableMap<String, Any> = mutableMapOf("price" to 20.5)
map += "arrange" to 0
map += "title" to "Night cream"
println(map.entries.joinToString(separator = ", "))
// price=20.5, arrange=0, title=Night cream
val bundle = bundleOf("price" to 20.5)
bundle.putAll(bundleOf("arrange" to 0))
bundle.putAll(bundleOf("title" to "Night cream"))
val bundleString =
bundle.keySet().joinToString(", ") { key -> "$key=${bundle[key]}" }
println(bundleString)
// arrange=0, price=20.5, title=Night cream