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.

Results 1 to 7 of 7

Thread: Array List

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Array List

    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??


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,307
    Thanks
    181
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default Re: Array List

    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

  3. #3
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Array List

    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!

  4. #4
    Junior Member shia's Avatar
    Join Date
    Sep 2011
    Location
    Manchester, UK
    Posts
    19
    My Mood
    Nerdy
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Default Re: Array List

    Quote Originally Posted by nadirkhan View Post
    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??
    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.

    else if - else if - else if... Goes Straight To Final else

  5. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,384
    My Mood
    Hungover
    Thanks
    144
    Thanked 628 Times in 538 Posts

    Default Re: Array List

    Quote Originally Posted by shia View Post
    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.

    else if - else if - else if... Goes Straight To Final else
    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!

  6. #6
    Junior Member shia's Avatar
    Join Date
    Sep 2011
    Location
    Manchester, UK
    Posts
    19
    My Mood
    Nerdy
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Default Re: Array List

    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.

  7. #7
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,384
    My Mood
    Hungover
    Thanks
    144
    Thanked 628 Times in 538 Posts

    Default Re: Array List

    Quote Originally Posted by shia View Post
    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!

Similar Threads

  1. Array List question
    By Demetrius82 in forum Java Theory & Questions
    Replies: 4
    Last Post: June 3rd, 2011, 10:28 AM
  2. Array list returns null
    By Scotty in forum Collections and Generics
    Replies: 3
    Last Post: April 14th, 2011, 06:50 AM
  3. Basic array list
    By Trunk Monkeey in forum What's Wrong With My Code?
    Replies: 5
    Last Post: January 24th, 2011, 10:51 AM
  4. Array List Doubt
    By mhnganesh in forum Collections and Generics
    Replies: 2
    Last Post: July 12th, 2010, 10:21 AM
  5. Doubt Regarding Printing an Array List
    By reeceypp in forum What's Wrong With My Code?
    Replies: 5
    Last Post: April 20th, 2010, 03:11 AM