查找ArrayList<Bean>的值

查找bean

fun main() {
    val list= ArrayList<Bean>()
    for (i in 0..10){
        list.add(Bean("pg$i","url$i"))
    }
    val bean=findPgInList("pg4",list)
    println(bean)
}
fun findPgInList(pg: String, list: ArrayList<Bean>): Bean? {
    list.forEach {
         if (it.pg == pg){
             return it
        }
    }
    return null
}
data class Bean(val pg:String,val url:String)

你可能感兴趣的:(服务器,linux,运维)