title: Check if color is already in array in Java
body: <p>I am working on a Java program that is making an array of colors that have been used in another array to draw a picture. I am stumbling on writing code that creates this new array, while also excluding colors that have been added to this array already.</p>
  
  <p>I would appreciate any help into where I am going wrong with my code.</p>
  
  <p>Thanks. My code is below:</p>
  
  <pre><code>public ArrayList&lt;Color&gt; getColorList()
  {
      ArrayList&lt;Color&gt; getColorList;
      getColorList = new ArrayList&lt;Color&gt;();
      int index = 0;
      boolean colorAdded = false;
      for(Stroke stroke : drawing){
          while(index &lt;= getColorList.size() &amp;&amp; colorAdded == false) {
          if(getColorList.get(index) == stroke.getColor()){
              colorAdded = true;
          }
          else{
              index = index + 1;
          }
      }
      if(colorAdded == false){
              getColorList.add(stroke.getColor());
          }
      index = 0;
      colorAdded = false;
      }
      return getColorList();
  }
  </code></pre>