U06-10-Copia de Arrays

static tipo[] copyOf(tipo origen[], int longitud);

int t[] = {1, 2, 1, 6, 23}; //tabla origen 
int a[], b[]; // tablas destino 
a = Arrays.copyOf(t, 3); //a = [1, 2, 1] 
b = Arrays.copyOf(t, 10); //b = [1, 2, 1, 6, 23, 0, 0, 0, 0, 0]

static tipo[] copyOfRange(tipo origen[], int desde, int hasta);

int t[] = {7, 5, 3, 1, 0, -2}; 
int a[] = Arrays.copyOfRange(t, 1, 4); //a = [5, 3, 1] 

voidSystem.arraycopy(ObjecttablaOrigen, intposOrigen, ObjecttablaDestino, intposDestino, int longitud);

int t[] = {1, 3, 4, 8}; 
int o[] = {9, 9, 9, 9}; 
System.arraycopy(t, 1, o, 2, 2); 
System.out.println (Arrays.toString(o)); 
//Muestra [9, 9, 3, 4]

Related Posts