title: Comparing elements in the same List Java
body: <p>I want to compare the elements in the same <code>List (The List "list)</code> and if they are the same print out a line, I'm fairly new to  programming and I dont yet completely understand the <strong>difference</strong> between <strong>List</strong> and an <strong>array</strong> and when you use them.</p>
  
  <p>Someone kindly suggested the code below and although it compliles nothing is being printed out. Since there are two pairs in my array I would expect something to print out at least once. Any help would be most appreciated thanks!</p>
  
  <pre><code>                        List&lt;Double&gt; list = new ArrayList&lt;Double&gt;();
  
                          while (search.find()){ 
                              list.add(Double.parseDouble(search.group(1)));
                          }
  
  
                          for(int i= 0 ; i &lt; list.size()-1; i++){
                              //System.out.println(list.get(i));  // Successfully prints out all doubles in the SHADING:BUILDING:DETAILED class
                              for(int k = i+1 ; k &lt; list.size() ; k++){
                                  if(list.get(i) == list.get(k)){
                                      System.out.println(i + "and" + k + "are pairs");
                                  }
                              }
                          }           
                      }
                  }
  </code></pre>