This week's book giveaway is in the Java 9 forum.
We're giving away four copies of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications and have Sander Mak & Paul Bakker on-line!
See this thread for details.
Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Array and mapping  RSS feed

 
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
Rancher
Posts: 2240
28
  • 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
Boost this thread!