title: JAVA: Preventing Duplicate Entries to an ArrayList
body: <p>I am trying to prevent duplicate entries from being added to an ArrayList as the list is being populated whilst reading through each line of a file. Each line of the file is in the format "node1 node2" (tab delimiter). A duplicate here could either be "node1 node2" or "node2 node1". Here is my code to try and perform this operation:</p>
  
  <pre><code>while((line = bufferedReader.readLine()) != null) {
  
       String delimiter = "\t";
       String[] tempnodelist;  
       tempnodelist = line.split(delimiter);
  
       for (int i=0; i &lt;= edgesnumber; i++) {   //edgesnumber = edges.size()
  
           if (tempnodelist[0] &amp;&amp; tempnodelist[1] != edges.get(i)) {
  
               edges.add(line);
  
              }
          }
  
       nodes.add(tempnodelist[0]);  
       nodes.add(tempnodelist[1]); //intial intended use of tempnodelist.
  </code></pre>
  
  <p>}</p>
  
  <p>Since I'm already splitting each line to make a HashSet of each node, I'm trying to use this to check for duplicates. At the moment I just can't seem to get the syntax right. How can I check through previous entries of the ArrayList for duplicates, and prevent them from being added, whist continuing to populate the ArrayList? what is wrong with this code currently?</p>
  
  <p>Please ask any questions if anything is unclear,</p>
  
  <p>Thanks in advance!</p>