zxc
zxc

Reputation: 1526

Which is faster creating multiple list or creating an object list?

I'm playing with 3 types of data to be inserted in a list. I'm wondering which is faster. Should I create 3 different lists or should I create an object list which have 3 variables in it?

Upvotes: 0

Views: 115

Answers (2)

davidhood2
davidhood2

Reputation: 1367

It would depend on what you want from it - if they are directly related and you only use the 3 data types together then , stick them in an object and create getters/setters for them.

If you need to access them independently then 3 separate lists may be better.

Before considering speed you should consider the functionality - there is no point storing 3 completely unrelated data types together.

Upvotes: 0

duffymo
duffymo

Reputation: 309008

It doesn't matter. This kind of micro-optimization is meaningless for performance.

You should write the code so it reads clearly and uses the best object encapsulation practices possible.

I would vote for better encapsulation - if those three disparate data types belong together, it's usually best to make that clear by encapsulating them in a single object so you can manage their state together.

Upvotes: 2

Related Questions