Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array Objects question

 
David Sundo
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a hard time to use the Array Objects.
Basically I would like store 3 String for each line dynamically.
For example: I would like to store in
Object[][] data;
The contents are as followed:
array 1 -->{"toyota", "1988", "green"}
array 2 -->{"honda", "1999", "white"}
Can anyone show me how to store dynamically? I do not want any initilization.
Greatly appreciated! Thank you!
-David Sundo
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi david
well, what i think about ur issue is, i observe that u haev information that seem to be related to the car object,
{
Make
Year,
Color
}
and u want to store such information dynamically...
why don't u create an object called,
class Car {
String make;
String year; // OR int??
String color;
}
and use ArrayList (basically List interfaces..) or Vector to add/remove such Car objects. u can do,
Car c1 = new Car("toyota","1982","red");
Car c2 = new Car("honda","1994","green");
...
and ArrayList al = new ArrayList();
al.add(c1);
al.add(c2);
if u have dynamic input u can do,
ArrayList al = new ArrayList() at beginning ofthe program and then at the point u get input write,
al.add(new Car(makeVar1, yearVar2, colorVar3));..
hope it helps..
regards
maulin
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't really understand your question, David. What exactly are you trying to accomplish?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic