0
I came up with a code here, it’s like this:
class Main {
Lista lista = new Lista();
public static void main(String[] args) {
i = 0;
String[] vetorExibir;
lista.exibicao(vetorExibir = new String[lista.lista.size()]);
while (i < vetorExibir.length) {
System.out.println(vetorExibir[i];
i++;
}
}
}
class Lista {
ArrayList<String> lista;
public Lista() {
lista = new ArrayList<>();
}
public String[] exibicao(String[] vetorExibir) {
int i = 0;
vetorExibir = new String[lista.size()];
while (i < lista.size()) {
vetorExibir[i] = lista.get(i);
} return vetorExibir;
}
}
Whereas Arraylist already has data.
It doesn’t work, it doesn’t display anything.
But why
lista.size()
would be 0? If there are items in Arraylist, it is larger than zero, right? Anyway, I will use your suggestion. She would be in the main method?– ptkato
you haven’t populated the Arraylist 'list' anywhere, so that’s zero at that point.
– Alécio Carvalho