my dog learned polymorphism*
The moose likes Beginning Java and the fly likes 2D Array Filling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "2D Array Filling" Watch "2D Array Filling" New topic
Author

2D Array Filling

Gavin Jones
Greenhorn

Joined: Dec 06, 2003
Posts: 1
Our problem is filling the 2D Array but with different variables!!!
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Hmm. You seem to be overwriting all the contents of the array everytime you add to it. Did you mean to do this?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jeffrey Hunter
Ranch Hand

Joined: Apr 16, 2004
Posts: 305
I'm assuming you're using your 2D array to model Car objects, so, essentially each row will model a Car, and each column will model the respective Car attributes (although it would be much cleaner, and object-oriented to simply use a single-dimensional List of Car objects, with the attributes encapsulated in the Car object itself).
Anyhow, using the 2D technique, you can have something as follows:

Realize, this is an awkward way to define Car objects, so if you need not use a 2D array, don't.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 2D Array Filling
 
Similar Threads
Result of the Code
Testing Strings
Convert 1d array to 2D boolean
Arrays. Making An array bigger???
Please Help