0

Let's say I have

Char[] one = {'a','b'};
Char[] two = {'c','d'};

What do I need to concatenate them?

Some code:

Random rand = new Random();

int Plength = 6;
char[] i = new char[Plength];
for (int x = 0; x < Plength; x++){
    i[x] = one[rand.nestIng(one.length)];
}
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • 1
    Define "connect". What do you want to achieve? – JB Nizet Apr 12 '17 at 18:23
  • Possible duplicate of [Combine and sort two arrays of different length in Java](http://stackoverflow.com/questions/13952127/combine-and-sort-two-arrays-of-different-length-in-java) – JustinKSU Apr 12 '17 at 18:40

1 Answers1

3

If you want to concatenate two arrays:

char[] array1 = ...
char[] array2 = ...

char[] result = new char[array1.length + array2.length];
System.arraycopy(array1, 0, result, 0, array1.length);
System.arraycopy(array2, 0, result, array1.length, array2.length);

result contains a concatenation.

Roman Puchkovskiy
  • 11,415
  • 5
  • 36
  • 72