Is it good to store different type of variable in arrayList as an objects? Or declared specific datatype for each arrrayList. | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

Is it good to store different type of variable in arrayList as an objects? Or declared specific datatype for each arrrayList.

16th Dec 2019, 11:22 AM
Abdul Wahab
Abdul Wahab - avatar
2 Respostas
+ 2
in my opinion use objects instead it's a good OOP practice to do so. it's better to have one arraylist containing all the attributes of an object than a bunch of arraylist containing just one attribute/datatype. let's say i want to store student informations into the program. the student have attribute name, age and grade. it's a much better implementation to create a class Student containing all their information and then store them as objects inside the arraylist. instead of making arraylist for each attribute. another reason is that adding and deleting objects is simpler and can be done in one line. if you have tons of arraylist you need to add the attributes one by one for each arraylist and it would affect speed and more lines needed. although i'm not sure if it would even affect the speed difference on the implementation.
16th Dec 2019, 1:14 PM
Shen Bapiro
Shen Bapiro - avatar
+ 1
Thanks
16th Dec 2019, 11:45 AM
Abdul Wahab
Abdul Wahab - avatar