I don't know how to remove an object from an ArrayList. I know there is remove but in my case, its more complicate.
I have a ArrayList (listsBlocksRemaining), which contains object that I put into another ArrayList (listBlocksIntoRibbon) when there are print. Then, what I want, its that the object that are print should be removed from listBlocksRemaining, there are print so no more remaining.
This is my code :
public void algoGlouton(Graphics g) {
int offsetX = 13;
int offsetY = 600;
int widthAvailable= 0;
int smallestHeight= 300;
for(Bloc b : listsBlocksRemaining) {
if(widthRemaining+b.getWidth () < ribbon.getWidth ()) {
widthAvailable+= b.getWidth();
g.setColor(b.getColor());
g.fillRect(offsetX, offsetY-b.getHeight(), b.getWidth(), b.getHauteur());
listBlocksIntoRibbon.add(b);
b.setX(offsetX);
b.setY(offsetY-b.getHauteur());
offsetX += b.getLargeur();
} else {
for(Bloc b1 : listBlocksIntoRibbon) {
if(b1.getHauteur() < smallestHeight) {
smallestHeight= b1.getHeight();
}
}
}
}
}
I tried this :
for(int i = 0; i<listsBlocksRemaining.size();i++) {
for(int j = 0; j<listBlocksIntoRibbon.size();j++) {
if(listsBlocksRemaining.get(i) == listBlocksIntoRibbon.get(j)) {
listsBlocksRemaining.remove(i);
}
}
}
and this :
for(int i = 0; i<listsBlocksRemaining.size();i++) {
Bloc b = listsBlocksRemaining.get(i);
if(listBlocksIntoRibbon.equals(b)) {
listsBlocksRemaining.remove(b);
}
}
Cordially
listsBlocksRemaining.removeAll(listBlocksIntoRibbon)does that. docs.oracle.com/javase/8/docs/api/java/util/…