Reputation: 2199
Is it better to have multiple lists or a single list? Currently I am using three lists to better organize a class I have for a project I am helping with. These three lists all hold the same class type but have different purposes and to be used at different times in the program. I originally split it up so I can easily distinguish between the classes in a JAXB xml generated file and to help with a module i created in netbeans, however I realized it could possibly be less taxing if i simply subclass say ArrayList (or if i put them in the correct order they will be used I could use LinkedList) and put all of the objects from the other three lists in it and simply add a method in the class going into the Array to help specify what type of class it is ie Passive Active Contact, I could also add three methods that would create smaller lists holding only the objects of one of the three types mentioned above. Right now the average size for all three lists together is about 6 to 10 What would be the best way to handle this should I leave it as is or create a large list of classes?
Upvotes: 0
Views: 107
Reputation: 9283
I would leave it as it is now. You said These three have different purposes and to be used at different times in the program
so it's natural to have them as 3 obiects, not as 1. You cannot mix resposibilities on you objects (and classes). If each of list is reponsible for different things, then they should be separate beings, even if they hold the same type of values.
Upvotes: 0
Reputation: 604
Because of the small number of elements, I would not focus on efficiency, but rather on the readability of your code, to avoid bugs and to make it easier to apply changes in the future. My guess it that in the case you describe readability is best served by having different lists, but you are in a better position to determine this.
Upvotes: 1