title: Repeating the elements of an array
body: <p>How can I repeat the elements of an array in Java?</p>
  
  <p>For example, given the array <code>{a,b,c,d,e,f}</code> and a number <code>n</code>, I want to produce an <code>n</code>-element array that looks like <code>{a,b,c,d,e,f,a,b,c,d,e,f,a,b,c,...}</code>.</p>
  
  <p>If I knew the length of the input and output arrays in advance, I could just write something like this:</p>
  
  <pre><code>int a=input[0], b=input[1], c=input[2], d=input[3], e=input[4], f=input[5];
  
  int[] array = new int[n];
  array[0]=a; array[1]=b; array[2]=c; array[3]=d; array[4]=e; array[5]=f;
  array[6]=a; array[7]=b; array[8]=c; array[9]=d; array[10]=e; array[11]=f;
  array[12]=a; array[13]=b; array[14]=c; // .. and so on
  </code></pre>
  
  <p>But how can I do this if I don't know the lengths yet?  I assume I would have to use a loop of some kind, but I'm not sure how to write one.  Or is there some built-in way to repeat an array in Java, like some other languages have?</p>