title: How to update values in HashMap with LinkedList?
body: <p>This is my HashMap:</p>
  
  <pre><code>public static HashMap&lt;String, LinkedList&lt;LinkedList&lt;String&gt;&gt;&gt; partitionMap;
  partitionMap = new HashMap&lt;String, LinkedList&lt;LinkedList&lt;String&gt;&gt;&gt;();
  </code></pre>
  
  <p>My program has a initial step of initialization where all keys are added, without values. After that, I need to retrieve the key and add the value.
  The problem is that I got the null pointer exception even if I initizalize the LinkedList.</p>
  
  <p>INIT step:</p>
  
  <pre><code>LinkedList&lt;LinkedList&lt;String&gt;&gt; ll = new LinkedList&lt;LinkedList&lt;String&gt;&gt;();
  partitionMap.put(key, ll);
  </code></pre>
  
  <p>After that:</p>
  
  <pre><code>LinkedList&lt;LinkedList&lt;String&gt;&gt; l = partitionMap.get(key);
  l.add(partition);  //CRASH, null pointer exception
  partitionMap.put(key, l);
  </code></pre>
  
  <p>The problem is related to the LinkedList and its initialization. Is there a way to avoid this problem?</p>
  
  <p>EDIT: full code.</p>
  
  <pre><code>   //This function is called N time to fill the partitionMap with only keys
     public void init(DLRParser.SignatureContext ctx) {
      LinkedList&lt;LinkedList&lt;String&gt;&gt; l = new LinkedList&lt;LinkedList&lt;String&gt;&gt;();
      partitionMap.put(ctx.getText(), l);
  }
  
    //After that, this function is called to fill partitionMap with only values
  public void processing(DLRParser.MultiProjectionContext ctx) {  
      LinkedList&lt;String&gt; partition = new LinkedList&lt;String&gt;();
      for (TerminalNode terminalNode : ctx.U()) {
          partition.add(terminalNode.getText());
      }
      Collections.reverse(partition);
  
      //iteration on another HashMap with the same keys, if we have a match
      //then add the values to the partitionMap
      for(Entry&lt;String, LinkedList&lt;String&gt;&gt; entry : tableMap.entrySet())
      {
          String key = entry.getKey();
          LinkedList&lt;String&gt; attributes = entry.getValue();
          if(attributes.containsAll(partition)) //match
          {
              //retrieve the LinkedList of LinkedList with value
              LinkedList&lt;LinkedList&lt;String&gt;&gt; l = partitionMap.get(key);
              l.add(partition); // CRASH - Nullpointer exception
              partitionMap.put(key, l); //add it -
              System.out.println(l.toString());
          }
      }
  }
  </code></pre>