Groovy -> Groovy 集合操作

List的增删改查

[1, 2, 3, 4]
[1, 2, 3, 4, 5, 6]
[2, 3, 4]
[3, 4]
[1, 2, 3, 4]
[3, 4, 10]
[3, 4, 20]
Element: 3
Element: 4
Element: 20
contains 3

// log
[1, 2, 3, 4]
[1, 2, 3, 4, 5, 6]
[2, 3, 4]
[3, 4]
[1, 2, 3, 4]
[3, 4, 10]
[3, 4, 20]
Element: 3
Element: 4
Element: 20
contains 3

Map的增删改查

// map的增删改查
def map = ["K":"Kotlin", "V":"View", "D":"Draw"]
// 增加
map.put("M", "Model")
map.each {key,value->
    println "Key: $key, Value: $value"
}
// 删除
map.remove("K") // 删除键
map.each {key,value->
    println "Key: $key, Value: $value"
}
map.remove("V", "View") // 删除键值对
map.each {key,value->
    println "Key: $key, Value: $value"
}
// 修改
map.D = "Data"
map.each {key,value->
    println "Key: $key, Value: $value"
}
map["D"] = "Drawable"
// 查找
map.each {key,value->
    println "Key: $key, Value: $value"
}
map.each {entry->
    println "Key: ${entry.key}, Value: ${entry.value}"
}

// log
Key: K, Value: Kotlin
Key: V, Value: View
Key: D, Value: Draw
Key: M, Value: Model
Key: V, Value: View
Key: D, Value: Draw
Key: M, Value: Model
Key: D, Value: Draw
Key: M, Value: Model
Key: D, Value: Data
Key: M, Value: Model
Key: D, Value: Drawable
Key: M, Value: Model
Key: D, Value: Drawable
Key: M, Value: Model

你可能感兴趣的:(Groovy,gradle,idea,开发语言)