Ano ang Java System.arraycopy() Method?
Pamamaraan ng Java System.arraycopy() Deklarasyon
Ang deklarasyon ng pamamaraan para sa java.lang.System.arraycopy() na pamamaraan sa klase ng java.lang ay ang mga sumusunod:
public static void arraycopy(Object src, int srcIndex, Object dest, int destIndex, int len)
Mga Parameter
Ang mga sumusunod ay ang mga parameter ng paraan ng arraycopy :-
src : Ito ang source array.
-
srcIndex : Ito ang panimulang index ng source array.
-
dest : Ito ang destination array.
-
destIndex : Ito ang panimulang index ng hanay ng patutunguhan.
-
len : Ito ang bilang ng mga elemento na kailangang kopyahin mula sa source array hanggang sa destination array.
Pag-andar
Kinokopya ng paraan ng arraycopy ang data mula sa src , simula sa srcIndex hanggang srcIndex +( len - 1) na mga elemento, hanggang sa dest array sa destIndex hanggang destIndex + ( len - 1).Ibalik ang Halaga
Ang arraycopy method ay may void return type na nangangahulugang hindi ito nagbabalik ng anuman.Halimbawa
public class Example {
public static void main(String[] args) {
String[] src = { "Monday","Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
String[] dest = { "January", "February", "March", "April", "May", "June", "July", "August"};
int srcIndex = 2;
int destIndex = 3;
int len = 2;
//print number of elements that need to be copied
//from the source to the destination array
System.out.println("len : " + len);
//print source index
System.out.println("srcIndex : " + srcIndex);
//print elements of the source array
System.out.print("src : ");
for (int i = 0; i < src.length; i++)
System.out.print(src[i] + " ");
System.out.println("");
//print destination index
System.out.println("destIndex : " + destIndex);
//print elements of the destination array
System.out.print("dest : ");
for (int i = 0; i < dest.length; i++)
System.out.print(dest[i] + " ");
System.out.println("");
// Use of arraycopy() method
System.arraycopy(src, srcIndex, dest, destIndex, len);
// this method copies the 'len' no of elements
// from the src array to the dest array using the srcIndex
// and destIndex as reference points in both the arrays
// Print elements of destination after
System.out.print("final destination array : ");
for (int i = 0; i < dest.length; i++)
System.out.print(dest[i] + " ");
}
}
Output
len : 2 srcIndex : 2 src : Lunes Martes Miyerkules Huwebes Biyernes Sabado Linggo destIndex : 3 dest : Enero Pebrero Marso Abril Mayo Hunyo Hulyo Agosto huling hantungan ng destinasyon : Enero Pebrero Marso Miyerkules Huwebes Hunyo Hulyo Agosto
Halimbawa ng pagbabago ng mga parameter
// Example of changing parameters
srcIndex = 4;
destIndex = 5;
len = 1;
Output
len : 1 srcIndex : 4 src : Lunes Martes Miyerkules Huwebes Biyernes Sabado Linggo destIndex : 5 dest : Enero Pebrero Marso Abril Mayo Hunyo Hulyo Agosto huling hantungan ng destinasyon : Enero Pebrero Marso Abril Mayo Biyernes Hulyo Agosto
GO TO FULL VERSION