This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
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

converting ArrayList to Object

 
charlie mills
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2542
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic