Android/kotlin/配列
提供: 初心者エンジニアの簡易メモ
配列for-in
var names:Array<String> if (names.isNotEmpty()) { for (name: String in names) { Log.d("test", "name=" + name) } }
配列プロパティ値取得
User.kt
class User { var name: String = "" }
var user = User() user.name = "taro" var user2 = User() user2.name = "jiro" var users: ArrayList<User> = arrayListOf(user, user2) for (user: User in users) { Log.i("test", "user.name=" + user.name) } var username = users.firstOrNull { it.name.contains("taro") }?.name ?: ""