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 413 views
1 answer 421 views
1 answer 358 views
2 answers 627 views
1 answer 375 views
4 answers 845 views
2 answers 467 views
...