Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

stuck with this array

 
Cougar Vis
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
coded this but for somereason it wont let me add a string into it, or do i need a different type of array?


[ November 28, 2004: Message edited by: Cougar Vis ]
 
Mike Gershman
Ranch Hand
Posts: 1272
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


You have to match a method signature:
public boolean add(Object o)
or
public void add(int index, Object element)

try this:
exits.add( "north" );
exits.add( "west" );

By the way,what are you doing with the formal parameter "theExits"?
 
Joel McNary
Bartender
Posts: 1824
Eclipse IDE Java Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the add method takes 1 parameter (well, there are versions that take ore than one, but none that takes two strings....)

What you need to do is break up the adding of things into the list into two separate commands:


Also, I would just declare the exits to be a List; this hids that fact that it is an array list and lets you replace it with any type of list later one (like a LinkedList). Not that that is likely to happen here, but it is a good habit to get into.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic