title: How can I manipulate 2D arrays in Java?
body: <p>I've been studying for my upcoming Java exam, and i'm having a hard time wrapping my head around 2D arrays. I have the basics down, such as creating and initializing a 2D array, but when it comes to inserting, deleting, or even sorting through one, I get pretty confused. My professor spent all of 10 minutes going over the basics but on our exam, we are expected to know how to create a 2D array of objects and manipulate the data by inserting, deleting, and sorting the objects in the array. He makes us hand-write all of our code on our exams, so no computers are allowed to assist in the process. I've spent hours pouring over examples both here and on other sites, but I still don't feel like I understand the material well enough to hand write all my code and get it right. </p>
  
  <p>My confusion mostly stems from the nested <code>for</code> loops usually used to move thru a 2D array. I can see how other people do it and copy that, but I still don't understand <em>why</em> the loops work as they do. I'm sure i'm in the minority here, but for whatever reason the logic behind it has me completely lost. </p>
  
  <p>Take this(albeit poor) example i've been working on to help myself understand 2D arrays(as well as the rest of the exam material). Say you run a car dealership and you want to order cars to fill your stock. The program starts with a top <code>abstract</code> class that describes the cars you are selling in general(in my case Audi). The dealership offers 4 models of Audi's, an <code>A4</code>, <code>A6</code>, <code>A8</code>, and <code>R8</code>. All these cars(classes) inherit methods from the <code>super</code>, named <code>Audi</code>. I then want to create a 2D array to store the cars in stock. This will be used in another class defined by me, including methods to <code>search()</code>, <code>delete()</code>, and <code>sort()</code>. Let's call it <code>AudiDealership</code>. The dealer can only hold 3 of each model, so the array would be something like <code>Audi[4][3]</code>. The A4's would fill the first row, <code>subscript 0</code>, A6 fills <code>subscript 1</code>, ect. How would I set up the <code>for</code> loops to insert/delete from the proper row? I obviously don't want an A4 inserted into a row that should hold an A6, and so on. </p>
  
  <p>Again, I can stare at code all day and copy it, but I want to <strong>understand</strong> <em>why</em>/<em>how</em> the loops work as they do. I apologize if this topic seems trivial or has been beaten to death, but all the reading i've done before posting this has left me just as confused as before. Many of you on this site are fantastic teachers in your own right, so I thought someone may be able to explain this in a way that I can understand. My professor hasn't been any help in this regard, so i'm using external means to try and figure things out. I greatly appreciate any advice or explanation in advance :) </p>