title: Data is being overridden strangely when I append a new object to an array of the same object type in Java
body: <p>So I have two objects. One titled 'drillingRecords' has two arrays for storing parsed line information from a file. The second titled 'drillingArray' contains an array to store 'drillingRecord' objects. The goal is to store one 'drillingArray' object within a 'drillingArray[]' for each line of data within the file. (I know they should be capitalized I'm just following the instructions given to me)</p>
  <p>I am reading through the file fine but a weird problem is occurring where the array is outputting the first line once, second line twice, and so on when iterated within the file reading while loop. The array appears to be overwriting the previous line's data. I believe this because once I tried to output the data outside of the while loop it outputs 10 lines containing the last line of file data.</p>
  <p>Here is the file reading method:</p>
  <pre><code>    String fileName = filePath;
      drillingArray[] drillerArray = new drillingArray[10];
      drillingRecord lineData;
      drillingArray recordHolder;
      BufferedReader br = new BufferedReader(new FileReader(fileName));
              
      int lineCount= 0;
      String line;
      line = br.readLine();
              
      while(line != null) {
          line=br.readLine();
          if(line != null) {
              String[] lineString = line.split(&quot;,&quot;);
              lineData = new drillingRecord(lineString);
              recordHolder = new drillingArray();
              recordHolder.add(lineData);
                  
              if( lineCount==drillerArray.length){
                  //possible issue in double drilling array although it does 
                  //successfully double the size
                  drillerArray = doubleDrillingArray(drillerArray);
              }
              drillerArray[lineCount]= new drillingArray(recordHolder);
              lineCount++;
          }
      }
          printData(drillerArray);
  }
  </code></pre>
  <p>The double array size method bc that could be an issue although it appears to work</p>
  <pre><code>private static drillingArray[] doubleDrillingArray(drillingArray[] currentDrillingArray)  {
          int dbleSize = currentDrillingArray.length*2;
          
          if (dbleSize &gt; 0 &amp;&amp; dbleSize &lt; Integer.MAX_VALUE) {
              drillingArray[] temp = new drillingArray[dbleSize];
              for (int i = 0; i &lt; currentDrillingArray.length; i++) {
                  temp[i] = currentDrillingArray[i];
                  currentDrillingArray = temp;
              }
          }else{
              System.out.println(&quot;no space&quot;);
          }
          return currentDrillingArray;
      }
  </code></pre>
  <p>And the method to print</p>
  <pre><code>public static void printData(drillingArray[] array) {
          for(int i = 0;i&lt;array.length;i++) {
              if(array[i] != null) {
                  System.out.println(array[i].data[0]);
              }
              else {
                  continue;
              }
          }
      }
  </code></pre>
  <p>I'm not sure where exactly data is getting overridden or copied inadvertently, and I would be extremely grateful if anyone with more experienced eyes could point me in the right direction. Let me know if you'd like any more information.</p>