What is the use of using an array list rather than an array?? When you display data in an array list by just iterating through the array, it displays just like it would in an array. So then why use array lists when you can use arrays??
Printable View
What is the use of using an array list rather than an array?? When you display data in an array list by just iterating through the array, it displays just like it would in an array. So then why use array lists when you can use arrays??
If you do not know the size of the array needed, how would you create it? Hence, an ArrayList whose size can be dynamically changed
Plus ArrayList has numerous methods to aid in managing the List, such as inserting, deleting, searching. Using an array you would have to provide all that functionality yourself.
Take a look at my post in the following thread to see an example of how to use an ArrayList. Compare it with the code in the first post of that thread where a simple array is used.
http://www.javaprogrammingforums.com...inal-else.html
That's exactly the OP's point here, and it's exactly my point in that thread- using an ArrayList in that case doesn't actually get you much. It's the cases that have already been outlined that ArrayList rocks. Not simple cases where you already know the order and the number of things you have.
Are you aware of the book Head First Java?
It teaches the use of ArrayList instead Array even in cases where you already know the order and number of items.
Yes that's fine, and I'll almost always use an ArrayList over an array- but you're not answering the OP of this thread's question (in fact you are demonstrating his point), and you are skipping ahead of what the OP in the other thread is supposed to be learning. That's not helpful, and in fact will come back to bite them. People need to learn how arrays work. Simply saying "just use an ArrayList" isn't helping.