How to create key value dictionary in Groovy

1 Answer

0 votes
def dict = [2: "groovy", 4: "c", 6: "java", 8: "rust", 5: "python"] 

println "key values:"
dict.each { println it }

println()
println "keys:"
dict.keySet().each { println it }

println()
println "values:"
dict.values().each { println it }




/*
run:

key values:
2=groovy
4=c
6=java
8=rust
5=python

keys:
2
4
6
8
5

values:
groovy
c
java
rust
python

*/

 



answered Dec 10, 2022 by avibootz

Related questions

1 answer 414 views
1 answer 427 views
1 answer 360 views
2 answers 628 views
1 answer 381 views
4 answers 852 views
2 answers 473 views
...