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

how to do this ?? should i use array or vector..

 
Roy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i got a question on whether i should use array or vector.. i need to define an multidimensional array..
i.e. array[name][money][time]..
but i do not know the size of the array.. i was reading that i can use vector or arraylist.. but i do not know if vector is able to take in the information like the above.. pls help.. if u can provide me with the starting code on how to declare vector and how to add the elements into the vector/arraylist.. i will be veri grateful..
 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would suggest that you stick with ArrayList.
Vector's methods are synchronized - thus there might
be a performance hit.
Pho
 
Roy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but how do i declare an arraylist with 3 different "headings".. for example, using array... i could do this
array[name][address][telephone]..
but for arraylist .. how do i define the arraylist to create the same functionalitiy as the array...
thanks..
 
John Sinues
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you store this information (name, address, telephone) in
a class then place the class in the ArrayList?
public class PersonInfo {
private String name;
private String address;
private String telephone;
PersonInfo( String name, String address, String telephone) {
this.name = name;
this.address = address;
this.telephone = telephone;
}
}
:
:
:
ArrayList info = new ArrayList();
info.add( new PersonInfo("name","address","phone") );
:
:
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roy,
Please change your name to be compliant with JavaRanch's naming policy.
Your ID should be 2 separate names with more than 1 letter each. We really want this to be a professional forum and would prefer that you use your REAL name.
Thanks,
Cindy
PS, if your name is not valid you do NOT qualify for the book giva away.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic