Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding to a two-dimensional array  RSS feed

 
Marcus Hathaway
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi this has been driving me mad, but how do you add data to a two dimensional array using a loop. I need the two dimensional array so i can populate a JTable. The array will originally pull its data from a database. In the java API they give an example such as:

Object[][] data =
{
{"Mars Bar", new Integer(2), new Double(23.50)},
{"Mily Way", new Integer(1), new Double(25.00)},
{"Whatever", new Integer(5), new Double(33.67)}
};

Ok now when applied this all works fine with the JTable. However, how could i populate that data array in a loop (assuming the string, integer and double valuse are coming from a database)? Just to make clear, i have no problem pulling data from a database, if i wanted to populate a one diemsinal array i'd be flying, but can't get this one to work.

Cheers, for any advice!
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


data.length is 10.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!