title: Searching a maptree of arrayLists
body: <p>I have a treemap of arrayLists.  I need to check each list for matching elements. My code works, except it's only checking the arrays against ones &lt;= itself. The other arrays track fine. I'd imagine it's a stupid error I'm missing, but..</p>
  
  <pre><code>            ArrayList&lt;Integer&gt; currentArray;
              ArrayList&lt;Integer&gt; compareArray;
  
              //Setting user friend list
  
                //cycle users "i"
                for(int i = 1; i &lt;= treemap.size(); i++){
                  currentArray = treemap.get(i);
  
                    //cycle user "k"
                      for(int k=1; k &lt;= treemap.size(); k++){
                        //if(i!=k){  Put back in once working
                          compareArray = treemap.get(k);
                          //cylce "k"s movie list
                          for(int l=0; l &lt; compareArray.size(); l++){
                            if(currentArray.contains(compareArray.get(l))){
                              if (treemap2.containsKey(i)){
                                ArrayList&lt;Integer&gt; list3 = treemap2.get(i);
                                list3.add(k);
                                treemap2.remove(i);
                                treemap2.put(i, list3);
                              }
                              if (!treemap2.containsKey(i)){
                                ArrayList&lt;Integer&gt; list4 =  new ArrayList&lt;Integer&gt;();
                                list4.add(k);
                                treemap2.put(i, list4);
                              }
                            }
                          }
                      }
                }
              //Create string of friends
              for(ArrayList&lt;Integer&gt;  x: treemap2.values()){
                str2 = Integer.toString(x.get(0));
                for (int i = 1; i &lt; x.size(); i++) 
                {
                    str2 = str2 + "," + Integer.toString(x.get(i)) ;
                }      
              }
  
              context.write(key, new Text(str2));
  </code></pre>
  
  <p>I still need to correct the key, that's easy and not getting used in the final program either way. </p>
  
  <p>I should be getting
  1   1,1,1,2,2
  2   1,1,2,2,2
  3   2,3,3,3</p>
  
  <p>Instead I'm getting
  1   1,1,1
  2   1,1,2,2,2
  3   2,3,3,3</p>
  
  <p>Either way, thank you in advance.
  Side note, doing the below gets me exactly what I want... Except it leaves out the last array....!!</p>
  
  <pre><code>        //cycle current array "i"
          for(int i = 1; i &lt; treemap.size(); i++){
            currentArray = treemap.get(i);
              //cycle compare array "k"
                for(int k=1; k &lt;= treemap.size(); k++){
                  if(i!=k){   //
                    compareArray = treemap.get(k);
                    //cylce array element in compare "l"
                    for(int l=0; l &lt; compareArray.size(); l++){
                      if(currentArray.contains(compareArray.get(l))){
                        if (treemap2.containsKey(i)){
                          ArrayList&lt;String&gt; list3 = treemap2.get(i);
                          list3.add(k+":"+compareArray.get(l));
                          treemap2.remove(i);
                          treemap2.put(i, list3);
                        }
                        if (!treemap2.containsKey(i)){
                          ArrayList&lt;String&gt; list4 =  new ArrayList&lt;String&gt;();
                          list4.add(k+":"+compareArray.get(l));
                          treemap2.put(i, list4);
                        }
                      }
                    }
                  }
                }
          }
  
  
  
  
  1   2105
  1   1953
  1   1339
  2   2105
  2   1321
  2   1339
  3   1321
  3   1544
  3   1222
  </code></pre>