I have the following code:
class Main {
public static void main(String[] args) {
Lista chamar = new Lista();
String[] vetor = {"Palavra", "Letra"};
chamar.adicionar(vetor);
}
}
class Lista {
ArrayList<String> lista;
public Lista() {
lista = new ArrayList<>();
} public void adicionar(String[] vetor) {
int i = 0;
while (i < vetor.length) {
lista.add(vetor[i]);
i++;
}
}
}
When I run, the error "OutOfMemoryError: Java heap space" appears, I would like to know how to fix it.