Check if color is already in array in Java

somonkey

New Member
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.I would appreciate any help into where I am going wrong with my code.Thanks. My code is below:\[code\]public ArrayList<Color> getColorList(){ ArrayList<Color> getColorList; getColorList = new ArrayList<Color>(); int index = 0; boolean colorAdded = false; for(Stroke stroke : drawing){ while(index <= getColorList.size() && 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\]
 
Back
Top