title: Scala - How to initialize a map of maps in scala?
body: <p>Trying to learn Scala. I want to initialize a Map of Maps.<br>
  My Java code would look something like this:  </p>
  
  <p><strong>(* Using computeIfAbsent)</strong></p>
  
  <pre><code> private static void initMap() {
      mapAdd(new App("ID_A", "Site1", "app_AAA", "A_A_A_A"));
      mapAdd(new App("ID_B", "Site1", "app_BBB", "B_B_B_B"));
      mapAdd(new App("ID_C", "Site2", "app_CCC", "C_C_C_C"));
      mapAdd(new App("ID_D", "Site2", "app_DDD", "D_D_D_D"));
  }
  
  private static void mapAdd(App app) {
      map.computeIfAbsent(app.siteId, x -&gt; new HashMap&lt;&gt;()).put(app.name, app);
  }
  </code></pre>
  
  <p>My Scala looks like this </p>
  
  <pre><code>val app1 = new AppKey("ID_A", "Site1", "app_AAA", "A_A_A_A")
  val app2 = new AppKey("ID_B", "Site1", "app_BBB", "B_B_B_B")
  val app3 = new AppKey("ID_C", "Site2", "app_CCC", "C_C_C_C")
  val app4 = new AppKey("ID_D", "Site2", "app_DDD", "D_D_D_D")
  
  val nameToAppKey1 = mutable.Map[String, AppKey](app1.name -&gt; app1)
  nameToAppKey1 += (app2.name -&gt; app2)
  
  val nameToAppKey2 = mutable.Map[String, AppKey](app3.name -&gt; app3)
  nameToAppKey2 += (app4.name -&gt; app4)
  
  map += ("Site1" -&gt; nameToAppKey1)
  map += ("Site2" -&gt; nameToAppKey2)
  </code></pre>
  
  <p>It looks like it's was written by a Java refugee.<br>
  What is the best practice to initialize a Map of Maps in Scala?</p>