How do I make an array larger?

I am trying to make a array, that if you get to the end, it gets one larger.
this is my code:

String[] text = new String[32];

int scroll;
int visScroll;
float scrollSpeed;

int lineHeight = 24;

void setup() {
  size(324, 522);
  textSize(14);

  for (int i = 0; i < 32; i++) {
    text[i] = i+"1";
  }
}

void draw() {
background(0);
  handleScrolling();
  for (int i = 0; i < height/lineHeight+2; i++) {
      try {
        fill(255);
        text(text[i-scroll], 10, visScroll+i*lineHeight+22);
      }
      catch (Exception E) {
        text = (String[]) expand(text);
      }
    }
}

void handleScrolling() {
  if (mousePressed) scrollSpeed = pmouseY-mouseY;
  visScroll -= scrollSpeed;
  scrollSpeed -= scrollSpeed/6;
  if (visScroll > lineHeight) {
    scroll++;
    visScroll = 0;
  }
  if (visScroll < -lineHeight) {
    scroll--;
    visScroll = 0;
  }
}

Forum.Processing.org/two/discussion/8080/why-use-arraylist-instead-of-array-with-append.html

1 Like