Two Laptop Bag
The moose likes Beginning Java and the fly likes converting ArrayList to Object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "converting ArrayList to Object" Watch "converting ArrayList to Object" New topic

converting ArrayList to Object

charlie mills
Ranch Hand

Joined: Nov 01, 2008
Posts: 49
I have read in data from a file (which is currently in an arrayList). I need to convert this arrayList into Object (ie. - Object[][] addresses = {{"Hancock", "Bob", "01202719029", "07676101393", "1 Seseme Street, London, AB8 8AE"}}; ) because I then need to display all the data from that file in a table(DefaultTabelModel)

I've got the data in an arraylist at the moment but I'm unsure of how to convert it.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2414
I have read in data from a file

Well, don't read it into an ArrayList. Read it into a Vector of Vectors instead, then you can create the JTable or DefaultTableModel directly from the Vector.
charlie mills
Ranch Hand

Joined: Nov 01, 2008
Posts: 49
Having looked up Vectors in the API, that does seem to make a lot more sense! Thanks

What is the difference between Object and Vector?

On a completely separate note, if I were to write data to the file that I have just read from, can I write the data as a String? (so I would write to the file as a string and read it out as a vector?)
I agree. Here's the link:
subject: converting ArrayList to Object
It's not a secret anymore!