Anonymous asked in Computers & InternetProgramming & Design · 8 years ago

Use array or arrayList?? Java programming help?

I am currently working on a project to play Poker with a computer player and I am coding in Java. I made a class called 'Card' and then I need to make a class 'Hand' which implements 5 instances of the Card class. Should I use an array or an arrayList to store the instances of the card class?

2 Answers

  • 8 years ago
    Favorite Answer

    It's better to use an ArrayList in this case. An array is for a fixed length, relatively static set of data. It takes a lot of work to make arrays handle changes to data.

    Since your hands will be variable in length (as cards are played and dealt out) and frequently changing, an ArrayList will save you a LOT of work. Imagine how much work it would take to deal with the 3rd card in an array being removed. ArrayList does all that for you.

  • 8 years ago

    Depends... do you need the extra methods available for use through the ArrayList class? Or can you get by with just an array? It's all about functionality... if you don't absolutely need something, then don't use it. No need to make things more complicated just because it may seem nicer.

Still have questions? Get your answers by asking now.