View Single Post
  #2 (permalink)  
Old 07-24-2007, 07:33 PM
shanePreater shanePreater is offline
Member
 
Join Date: Jul 2007
Location: England, Bath
Posts: 47
shanePreater is on a distinguished road
Is the array you are creating a fixed size? If so and if you know the size you can simply create an array of Item objects ala:
Code:
Item itemList = new Item[size]; itemList[0] = new Item("club", 1, "A Club"); ...
However if you don't know the array size or if it is likely to change then your probably better off with an array:
Code:
List<Item> itemList = new ArrayList<Item>(); itemList.add(new Item("club", 1, "A Club")); ...
Then when you wish to retrieve an item at a given index use:
Code:
Item chosenItem = arrayList.get(index);
The generics and collections stuff in java is very similar to the STL stuff in C++ so if you have used that then your laughing, if not, its not too hard to pick up.

If you are using a JDK prior to 1.5 then drop the <> sections and cast the item returned from the get method to an Item.

Hope that helps.
__________________
Shane Preater -
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Reply With Quote