This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "2D Array Filling" Watch "2D Array Filling" New topic

2D Array Filling

Gavin Jones

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

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:
subject: 2D Array Filling
Similar Threads
Result of the Code
Arrays. Making An array bigger???
Testing Strings
Convert 1d array to 2D boolean
Please Help