title: Issue in updating elements in multidimensional vector in java?
body: <p>I am trying to update elements in 2D Vector(in fact I am creating a ((n*n) xn) matrix ) based on a condition which I will mention in the sample code.</p>
  
  <p>Here is the sample code.</p>
  
  <pre><code>public class TestMatrix{
      private Vector&lt;Vector&lt;Integer&gt;&gt; matrix = new Vector&lt;Vector&lt;Integer&gt;&gt;();
  
      public void matrixUpdate(){
          int n = 9;
          Vector&lt;Integer&gt; tmpMatrix = new Vector&lt;Integer&gt;();
          for(int i = 0;i &lt; n;i++) tmpMatrix.addElement(-1);  // initialize 
                                                        //tmpMatrix
          for(int j = 0; j &lt; n*n; j++){
              marix.addElement(tmpMatrix);
          }  // initialize matrix
          for(int i = 0; i &lt; n*n; i++){
              for(int j = 0; j &lt; n; j++){
                 int a = i/n; 
                 int b = i%n;
                 int c = j;
                 System.out.print("r" + a + "r" + b + "r" + c + "\t");
                 //condition for updating elements
                 if(a == b){
                     matrix.get(i).set(j,-1);
                     continue;
                 }
                 if(b == c){
                     matrix.get(i).set(j,-1);
                     continue;
                 }
                 if(a == c) {
                     matrix.get(i).set(j,-1);
                     continue;
                 }
                 matrix.get(i).set(j,99);
              }
              System.out.println(matrix.get(i));
          }
          for(int i = 0;i &lt; (n*n); i++){
              System.out.println(matrix.get(i));
          }
      }
  
      public static void main(String[] args){
          TestMatrix testMatrix = new TestMatrix();
          testMatrix.matrixUpdate();
      }
  }
  </code></pre>
  
  <p>You can run the above code and check for yourselves. As per the output that I got it is not what I am expecting. </p>
  
  <p>Any help is appreciable. Better implementation of the above logic is deeply appreciable.</p>
  
  <p>Cheers.</p>
  
  <p>Edit: Expected result (for n=8 a n*n size vector with each element as a n-size vector):</p>
  
  <pre><code>[
    [99 -1 -1 -1 -1 -1 -1 -1],
    [99 99 -1 -1 -1 -1 -1 -1],
    [99 -1 99 -1 -1 -1 -1 -1],
    [99 -1 -1 99 -1 -1 -1 -1],
    [99 -1 -1 -1 99 -1 -1 -1],
    [99 -1 -1 -1 -1 99 -1 -1],
    [99 -1 -1 -1 -1 -1 99 -1],
    [99 -1 -1 -1 -1 -1 -1 99],
    [99 99 -1 -1 -1 -1 -1 -1],
    [-1 99 -1 -1 -1 -1 -1 -1],
     ... total 64 lines ...
  ]
  </code></pre>