File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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
It's not a secret anymore!