title: Detect collisions between objects in arrays
body: <p>So I need to detect the collision of multiple objects that are stored in two different arrays or arrayLists. I have confirmed that the collision detection method itself is functioning properly. The problem is that the objects colliding are supposed to disappear and be removed from the array, and I'm not sure how to go about this.</p>
  
  <pre><code> public class GamePanel extends PApplet{
  private boolean myRunningStatus;
  private final int HEIGHT = 700;
  private final int WIDTH = 1200;
  private final int SHOT_SPEED = -20;
  private int numStars = 0, numEnemies = 0;
  private Hero hero;
  private Enemy[] enemies; 
  private List &lt;Star&gt; stars;
  
  public GamePanel(){
      myRunningStatus = true;
      createEnemies();
      createStars();
      createHero();
      updateEnemies();
  }
  
  public void createEnemies(){
      enemies = new Enemy[10];
      for (int i=0; i&lt;enemies.length; i++){
          enemies[i] = new Enemy(random(1, WIDTH), random(1, HEIGHT), 5, 20);
      }
  }
  
  public void createHero(){
      hero = new Hero(mouseX, mouseY);
  }
  
  public void createStars(){
      stars = new ArrayList &lt;Star&gt;();
  }
  
  public Star generateStar(){
      Star star = new Star(hero.getHeroX(), hero.getHeroY());
      return star;
  }
  
  
  public void setup(){
    background(255);
    size(WIDTH, HEIGHT);
    hero.render(this);
  }
  
  public void draw(){
  if(myRunningStatus){
    background(255);
    hero.render(this);
   for(int i=0; i&lt;enemies.length; i++){
    enemies[i].render(this);
    enemies[i].move();
   }
       for(int i=0; i&lt;stars.size(); i++){
           if(stars.get(i) != null){
               stars.get(i).render(this);
               stars.get(i).move(SHOT_SPEED);
               if(stars.get(i).getYPos() &lt; 0){
                   stars.remove(i);
           }
       }
   }
  }
  }
  
  //this is the method I'm using to find the collisions between the objects and remove them
  public void updateEnemies(){
      for(int i=0; i&lt;enemies.length; i++){
      for(int j=0; j&lt;stars.size(); j++){
          if(enemies[i].starHit(stars.get(j))){
              stars.set(j, null);
              enemies[i] = null;
          }
          }
      }
  }
  
  
  public void mouseMoved(){
  if(myRunningStatus){
    hero.setHeroX(mouseX);
    hero.setHeroY(mouseY);
      }
  }
  
  public void mouseClicked(){
       for (int i=0; i&lt;10;){
               stars.add(i, generateStar());
               break;
       }
  }
  </code></pre>