# ArrayList Problems / get() & remove()

**URL:** <https://discourse.processing.org/t/arraylist-problems-get-remove/1150>\
**Category:** Coding Questions\
**Created:** [June 21, 2018, 1:18pm UTC](https://discourse.processing.org/t/arraylist-problems-get-remove/1150 "2018-06-21T13:18:55Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [July 10, 2018, 10:20am UTC](https://discourse.processing.org/t/arraylist-problems-get-remove/1150/9 "2018-07-10T10:20:06Z")

</div>

It’s going to be easy to remove the bullets that hit from your ArrayList because an ArrayList is specifically designed to allow you to remove elements from it.

Removing a single Alien from an Array of Aliens is not going to be as easy.

So… why are you using an Array of Aliens, instead of an ArrayList of them? You don’t actually need space for 1000 aliens at a time. Just a few that are on the screen.

Anyway, I’m getting ahead of myself. You want to do collisions. You need to check - for each alien - if any bullet is hitting it.

Thus you will first need to loop over every alien.

```
for ( each alien ){

```

Then you will need to loop ove each bullet.

```
  for( each bullet ) {

```

Then you need to see if those collide.

```
if( alien.collides( bullet ) ){

```

If so, you remove that alien and that bullet.

* * *

When is a round bullet colliding with a round alien? Basically, when are two circles intersecting? What can you say about the distance between their centers in relationship to the sum of their radii?

* * *

You might see this thread I posted recently:

> [@Problem With Collision](https://discourse.processing.org/t/problem-with-collision/1539/9):
>
> Anyway. Collisions. Since the thing that we really care about colliding with is enemies, let’s loop over every enemy. if we collide that enemy with the player, the player dies. Then let’s loop over all the bullets. If that enemy collides with that bullet, both that enemy and that bullet die. … What does it mean for an object to die? Well, we can add an alive boolean to each of our objects. And then only draw them if they are alive. And of course only alive things can cause collisions. class P…

---

_[View the full topic](https://discourse.processing.org/t/arraylist-problems-get-remove/1150)._
