Skip to content

Commit

Permalink
add map-demo 7
Browse files Browse the repository at this point in the history
  • Loading branch information
yennan.liu committed Jan 21, 2022
1 parent 45c7797 commit bea0d24
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
- [MapDemo_4](./src/main/scala/ScalaBasic/MapDemo_4.scala)
- [MapDemo_5](./src/main/scala/ScalaBasic/MapDemo_5.scala)
- [MapDemo_6](./src/main/scala/ScalaBasic/MapDemo_6.scala) : map get values demo
- [MapDemo_7](./src/main/scala/ScalaBasic/MapDemo_7.scala) : for insert map demo
- [JavaMap1](./src/main/scala/ScalaBasic/JavaMap1.java) : java Map demo
- Scala `Map` basic op, properties
- HashMap
Expand Down
15 changes: 15 additions & 0 deletions src/main/scala/ScalaBasic/MapDemo_7.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package ScalaBasic

// https://stackoverflow.com/questions/31345090/create-map-in-scala-using-loop

object MapDemo_7 extends App {

var myMap1: Map[String, Int] = Map()

for (i <- 1 to 7){
println(i)
myMap1 += (s"key-$i" -> i)
}

println(myMap1.toString())
}

0 comments on commit bea0d24

Please sign in to comment.