title: "Generic" solution for primitive array?
body: <p>I have classes that for processing primitive array input: CharArrayExtractor for char[], ByteArrayExtractor for byte[], IntegerArrayExtractor for int[], ... </p>
  
  <pre><code>public void CharArrayExtractor {
  
      public List&lt;Record&gt; extract(char[] source) {
          List&lt;Record&gt; records = new ArrayList&lt;Record&gt;();
          int recordStartFlagPos = -1;
          int recordEndFlagPos = -1;
          for (int i = 0; i &lt; source.length; i++) {
              if (source[i] == RECORD_START_FLAG) {
                  recordStartFlagPos = i;
              } else if (source[i] == RECORD_END_FLAG) {
                  recordEndFlagPos = i;
              }
              if (recordStartFlagPos != -1 &amp;&amp; recordEndFlagPos != -1) {
                  Record newRecord = makeRecord(source, recordStartFlagPos,
                          recordEndFlagPos);
                  records.add(newRecord);
                  recordStartFlagPos = -1;
                  recordEngFlagPos = -1;
              }
          }
      }
  }
  
  public void ByteArrayExtractor {
  
      public List&lt;Record&gt; extract(byte[] source) {
          // filter and extract data from the array.
      }
  }
  
  public void IntegerArrayExtractor {
  
      public List&lt;Record&gt; extract(int[] source) {
          // filter and extract data from the array.
      }
  }
  </code></pre>
  
  <p>The problem here is that the algorithm for extracting the data is the same, only the types of input are different.  Everytime the algorithm changes, I have to change all of the extractor classes.</p>
  
  <p>Is there a way to make extractor classes more "generics"?</p>
  
  <p>Best regards.</p>
  
  <p><strong>EDIT</strong>: It seems that every suggestion so far is to use autoboxing to archive generic. But the number of elements of the array is often large, so I avoid using autoboxing.</p>
  
  <p>I added more specific implementation of how the data is being extracted. Hope it will clarify something.</p>