Results 1 to 8 of 8
Thread: help with an array.
- 05-30-2008, 08:58 PM #1
help with an array.
ok so i am making a text based rpg (i know not that great) and i am having a few problems with the array for my equipment class. i dont know how to start it. could anyone help me? i want to be able to store the weapons and armor and some items.
thank you.Last edited by f_the_cook; 05-30-2008 at 10:05 PM.
- 05-31-2008, 02:20 AM #2
You may read about When to use an array, and when to use ArrayList/List or AbstractList.
freedom exists in the world of ideas
- 05-31-2008, 06:40 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Yes, first you should go through on each of them and get a brief idea. Depend on your requirement can choose a best one. Think that, your collection is dynamically changed all the time.
- 05-31-2008, 08:24 PM #4
Member
- Join Date
- Apr 2008
- Posts
- 88
- Rep Power
- 0
Very short lesson (if im correct God willing) would be like this:
String[] armorArray = {"Gold Armor", "Bronze Armor", "Leather Armor", "Poet's Drapery"};
That would set 4 values being those 4 armor types to an array called "armorArray"
String[] can be transliterated as "String Array"
Anyway once you have it set they will be set at index values of 0-3 (4 armors, but we start with 0 representing Gold Armor)
Then you would look into writing code on calling them, im not too sure on that part but it might be like
{if (userInput.equals("Gold Armor"))
String armorType = armorArray[0]}
Someone correct me on this if im wrong.
- 06-02-2008, 12:20 PM #5
that may be good, if the length of that array is just less than 10....
how about 5000?
Will you compare them one by one?
Searching through loop maybe good.... if you will use binary search algorithm....
Another lines of code.... :(
ArrayList will do the rest....freedom exists in the world of ideas
- 06-02-2008, 01:01 PM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Yep, binary search is the best. As sukatoa said if you have large number of elements this can be a real mess.
- 06-02-2008, 05:38 PM #7
Member
- Join Date
- Mar 2008
- Posts
- 6
- Rep Power
- 0
Binary search if the elements are ordered... Which means every time you add something - you need to search for its place... :(
- 06-03-2008, 04:05 AM #8
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Yes, why is that difficult. That is the best way to handle dynamically change the size of the array. Actually a list.
Similar Threads
-
Array Reflection: Multi Array Reflection
By Java Tip in forum java.langReplies: 0Last Post: 04-23-2008, 08:08 PM -
Array Help
By bluegreen7hi in forum New To JavaReplies: 2Last Post: 03-28-2008, 02:25 AM -
can anyone help... 2d Array
By Mark1989 in forum New To JavaReplies: 2Last Post: 03-12-2008, 08:59 PM -
Would appreciate your help with 2d Array..
By cloudkicker in forum New To JavaReplies: 1Last Post: 02-11-2008, 02:34 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks