1
For example, if I need to create arraylists for each person q register in my system:
ArrayList pessoa1 ArrayList();
ArrayList pessoa2 ArrayList();
ArrayList pessoa3 ArrayList();
The problem is I don’t know how many people are going to register so it would have to be created dynamically, like:
for(int i = 0; i < numeroPessoasCadastradas; i++){
pessoa[i] = new ArrayList();
}
It’s possible to do something like that?
Yes, perfectly possible. Arraylist has no set size. It even has a size but expands as it is filled.
– user28595
Hello, I tried to create this for but java gives me the following error: Exception in thread "main" java.lang.Nullpointerexception
– Thiago
So it would be interesting to better explain the problem, because it was not very clear the purpose of this.
– user28595
Probably the Arraylist
pessoa
was not created.– ramaral
Try to start
pessoa
before. You are using a vector ofArrayList
, which is strange to me; anyway, you could, before thefor
, dopessoa = new ArrayList[numeroPessoasCadastradas]
, but it’s very strange to do this. What is the context of you needing to do this? Why theArrayList
s are not typed?– Jefferson Quesado
@Thiago, I’d like to add an addendum on Arraylist: here. I believe I can help in understanding your question. In your solution you use Arraylist.
– pss1suporte