Results 1 to 3 of 3
Thread: Simple ArrayList Q
- 04-04-2011, 10:27 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 2
- Rep Power
- 0
Simple ArrayList Q
Hi,
I hope this is an easy question to answer for you.
I am making a card game that has a Card class and a Deck class. I am using an ArrayList to represent the cards in the deck, but I'm unsure on one particular part of the code.
This is what I have so far, what is confusing me is how initialDeck is a parameter in the constructor. Is this meant to be used in the ArrayList and if so, how do I do this?Java Code:public class Deck { private ArrayList<Card> deck; private Card[] initialDeck; /** * Create a new deck from an initial set of cards. * */ public Deck(Card[] initialDeck) { super(); this.initialDeck = initialDeck; deck = new ArrayList<Card>();
Thanks in advance if you can help!
-
Sorry, but your question doesn't make any sense. Yes initialDeck is a parameter, is what meant to be used in the ArrayList?
Card[] is an Array of Card
deck is an ArrayList of Card
Are you intentionally using a mix of both?
to add an Array to ArrayList use java.util.Arrays.asList e.g.
Java Code:Card[] initialDeck = new Card[52]; java.util.List<Card> cardList = new java.util.ArrayList<Card>(); cardList.addAll(java.util.Arrays.asList(initialDeck));
- 04-05-2011, 01:57 AM #3
Member
- Join Date
- Apr 2011
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
copying contents of an ArrayList to another ArrayList
By ankit1801 in forum New To JavaReplies: 8Last Post: 03-27-2011, 06:07 AM -
sorting arraylist based on another arraylist
By busdude in forum New To JavaReplies: 4Last Post: 02-07-2011, 11:48 AM -
how to add Arraylist filter for a jsp page showing results from a servlet-Arraylist
By alok_sharma in forum Java ServletReplies: 7Last Post: 11-22-2010, 01:26 PM -
A private static ArrayList hold an object and static getter ArrayList
By Louis in forum New To JavaReplies: 2Last Post: 11-16-2010, 05:51 PM -
Java Project Trouble: Searching one ArrayList with another ArrayList
By BC2210 in forum New To JavaReplies: 2Last Post: 04-21-2008, 11:43 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks