In Java 8, you could do this using Stream.flatMap():
int n = 2;
Card[] cards = IntStream.range(0, n) // repeat n times
.mapToObj(i -> masterPack) // replace each i with the masterPack
.flatMap(pack -> Arrays.stream(pack)) // turn the Stream<Card[]> into a Stream<Card> by flattening it
.toArray(Card[]::new); // create a new array containing all the cards repeated n times
If you can't use Java 8, you could use System.arraycopy():
arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
Parameters:
src - the source array.
srcPos - starting position in the source array.
dest - the destination array.
destPos - starting position in the destination data.
length - the number of array elements to be copied.
For example, if you wanted to copy the masterPack to a new deck with double its size, you could do:
int n = 2;
Card[] cards = new Card[masterPack.length * n];
for (int i = 0; i < n; i++) {
System.arraycopy(masterPack, 0, cards, i * masterPack.length, masterPack.length);
}
This will loop twice, doing:
System.arraycopy(masterPack, 0, cards, 0, 52);
System.arraycopy(masterPack, 0, cards, 52, 52);
The first iteration will copy the masterPack elements to positions 0 to 51 and the second iteration to positions 52 to 103 in the cards array.
Your Card objects should probably be immutable, so there is no need to create new Card copies every time. Referencing the same 52 objects should be faster and take less memory.
System.arraycopy