• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

When to use arrays vs Lists?

 
Sam O'Neill
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to store my flight data in an array in my model primarily because I want to be able to index into it, I have no need to dynamically insert data or to increase or decrease the array's size and I don't require any synchronization.
Does anyone have any good reasons why I should in fact use a List instead of an array, apart from those mentioned above, as I always struggle with this decision?
My view currently gets an array of Flight objects from my model to set the JTable's TableModel with and I am not sure whether to return a List instead as I can't see the advantage of one over the other at the moment.
Any thoughts on the subject?
Thanks
sam
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You know it is a funny thing, there are always more than one way to complete and assignment.
In this assignment I sent DataInfo[] to my TableModel, because that is what the Data class gave to me.
I chose it because I didn't want to have to convert Arrays to Lists and Lists to Arrays back and forth, when I can just use one to go all the way and save some code lines.
So sometimes the chose is down to what is easier to code and maintain. And sometimes it is down to which has the most functionality that I need, etc. It is always a case by case decision, and also one that always have trade offs that you need to decide for yourself if it is worth it.
Mark
 
Sam O'Neill
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mark - you're a gem
Sam
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic