Java while loop

can somebody tell me why this is not working …

import java.util.ArrayList;

public class lunch {
public static void main(String args) {

    ArrayList<String> hey = new ArrayList<String>();

    hey.add("wake up to reality");
    hey.add("nothing ever goes as planned");
    hey.add("in this acursed world");
    hey.add("the longer you live the more");
    hey.add("you will realise");
    hey.add("that only thing exist in this world");
    hey.add(" are pain,suffering,futility");

    int i = 0;

    while (i < hey.size()) {

        if (hey.get(i).equals("hahahahah")) {

        } else {



( It is not removing hahaha text from the array )

I don’t think that’s the problem.
The problem seems to you’re trying to access an invalid index when you try to print to the console/screen.

this is done after the index is increased (incremented) with the i++
so if you leave it on that line you’d have to use System.out.println(hey.get(i - 1));

Some alternatives are to move the printing to inside the else-block, before the i++; or to make a separate loop just for printing.