How to declare class list?

1

I have a class Usuario that will have a list of class Pastas , and this class will have a list of class Questão .

public class Usuario{
     String nome; 
     ArrayList< Pasta > listaPasta;
}

My problem is not knowing if this placement is right, because in my head, I want to create the Usuario class and have the list created, or if I have to create it out after creating the class and giving a SetListaPasta() .

    
asked by anonymous 30.04.2018 / 03:31

1 answer

1

We can not know why you do not have more information on the question. Programming is less write code and more understand the problem and know what to do (not how to do).

It seems to me that this is correct, you should only initialize the list, as it is currently null. Of course you can boot into the builder as well.

You may already put the value of the list in the constructor, or you can add the items in it.

It is possible to have a SetListaPasta() , but almost always this is an error, it would make sense to have a method that adds folders to the list. But maybe not the ideal. It depends on the requirement that we do not know.

Everything is valid as needed.

    
30.04.2018 / 04:19