title: Building a method that reads and prints partially filled array in java
body: <p>As part of my program I need to build a method that will read and print only the filled slots of the array no matter where they are.  By that I mean if there was an array length ten and only array[0] and array[9] were filled the method should read the entire array and only print whats been filled and not the zeros in between.</p>
  
  <p>This is how the method will look</p>
  
  <pre><code>printArray( intList, countOfInts );
  </code></pre>
  
  <p>This is the method I've built:</p>
  
  <pre><code>static public int printArray( int[] intList, int countofInts)
   {
      for (countofInts = 0; countofInts &lt; intList.length; countofInts++)
      { 
          System.out.print(intList[countofInts] + "\t ");
      }
      return countofInts;
  
   }
  </code></pre>
  
  <p>It works but it prints the whole array instead of just the slots that are filled.
  How do I make it not print the slots of the array that aren't filled?</p>