public class ConcatTableaux {Sortie
public static void main(String[] args) {
String[] t1 = {"1","2","3"};
String[] t2 = {"4","5","6"};
String[] t12 = new String[t1.length+t2.length];
/*Concaténation*/
for(int i = 0 ; i < t1.length; i++)
t12[i]=t1[i];
for(int i = 0 ; i < t2.length; i++)
//on continue le copiage dans t12 à partir de l'indice
//dont on a arrêter qui est la longueur de t1
t12[i+t1.length]=t2[i];
for(int i = 0 ; i < t12.length; i++)
System.out.println(t12[i]);
}
}
1
2
3
4
5
6
public class ConcatTableaux {Sortie
public static void main(String[] args) {
char[] t1 = {'a','b','c'};
char[] t2 = {'d','e','f'};
char[] t12 = new char[t1.length+t2.length];
//copie du premier tableau
System.arraycopy(t1, 0, t12, 0, t1.length);
//copie du deuxième tableau tableau
System.arraycopy(t2, 0, t12, t1.length, t2.length);
for(int i = 0 ; i < t12.length; i++)
System.out.println(t12[i]);
}
}
aRéférences
b
c
d
e
f
Please disable your ad blocker and refresh the window to use this website.