just trying to add the nth element from a char array to an Array list. However, I will get an ArrayIndexOutOfBoundsException when I try to run my following method. I am guessing it is because of my x[i+2] doesn't work when the array reaches its end? 

Here's my code for my method:

```
public void Encode (char[] x){
    for(int i = 3; i < x.length; i++) {

        mid.add(x[i+1]);
        bottom.add(x[i+2]);
        top.add(x[i]);
        top.removeAll(mid);
        top.removeAll(bottom);
    }
} 

 public ArrayList getTop(){
    return top;
}

public ArrayList getMid() {
    return mid;
}

public ArrayList getBottom() {
    return bottom;
}

```

}