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??
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
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.
Improving the world one idiot at a time!
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.
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
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.
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!