Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array and mapping

 
Joseph Smithern
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have something that works with data mapping but was wondering if I can add an array in the add method part:

Change this -> myMap.add(firstname + "," + lastname + "," + address);
To something like this? -> myMap.add(array instead here...);


Here is what I have now:



output:

Please advise.
[ July 06, 2008: Message edited by: Joseph Smithern ]
 
Norm Radder
Bartender
Posts: 1348
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you read the API doc for the add() method?
public boolean add(E e)

It looks like you can add any object.
Have you tried coding and compiling and executing a simple example?
Write a 10 line program and see what happens.
 
Santhosh Kumar
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
List.add() method takes Object as input to add to the list so it means you can sure add an array instead of a String but beware that when you call get(0), you will get the same array back.

If this is not what you expect (to add array instead of elements in it), you can subclass the arraylist and override the add method to do just that.
[ July 06, 2008: Message edited by: Santhosh Kumar ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic