title: Java 8 map compute with set as value
body: <p>My map looks like this      </p>
  
  <pre><code>private Map&lt;String, LinkedHashSet&lt;String&gt;&gt; map = new HashMap&lt;&gt;();
  </code></pre>
  
  <p>in traditional approach I can add value to map with key check as below</p>
  
  <pre><code>public void addEdge(String node1, String node2) {
          LinkedHashSet&lt;String&gt; adjacent = map.get(node1);
          if (adjacent == null) {
              adjacent = new LinkedHashSet();
              map.put(node1, adjacent);
          }
          adjacent.add(node2);
      }
  </code></pre>
  
  <p>with java 8, I can do something like this, with this one also I'm getting same output.</p>
  
  <pre><code>map.compute(node1, (k,v)-&gt; {
              if(v==null) {
                  v=new LinkedHashSet&lt;&gt;();
              }
              v.add(node2);
              return v;
              });
  </code></pre>
  
  <p>is there any better way to do with java 8?</p>