Java System.arraycopy() पद्धत काय आहे?
Java System.arraycopy() पद्धत घोषणा
java.lang वर्गातील java.lang.System.arraycopy() पद्धतीसाठी पद्धत घोषणा खालीलप्रमाणे आहे:
public static void arraycopy(Object src, int srcIndex, Object dest, int destIndex, int len)
पॅरामीटर्स
अॅरेकॉपी पद्धतीचे पॅरामीटर्स खालीलप्रमाणे आहेत :-
src : हे स्त्रोत अॅरे आहे.
-
srcIndex : ही सोर्स अॅरेची सुरुवातीची अनुक्रमणिका आहे.
-
dest : हे गंतव्य अॅरे आहे.
-
destIndex : ही डेस्टिनेशन अॅरेची सुरुवातीची अनुक्रमणिका आहे.
-
len : ही घटकांची संख्या आहे जी स्त्रोत अॅरेमधून गंतव्य अॅरेमध्ये कॉपी करणे आवश्यक आहे.
कार्यक्षमता
अॅरेकॉपी पद्धत src वरून डेटा कॉपी करते , srcIndex पासून srcIndex +( len - 1 ) घटकांपर्यंत, destIndex वर destIndex + ( len - 1 ) पर्यंत डेस्ट अॅरेवर .रिटर्न व्हॅल्यू
अॅरेकॉपी पद्धतीमध्ये व्हॉइड रिटर्न प्रकार आहे ज्याचा अर्थ ती काहीही परत करत नाही.उदाहरण
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] + " ");
}
}
आउटपुट
len : 2 srcIndex : 2 src : सोमवार मंगळवार बुधवार गुरुवार शुक्रवार शनिवार रविवार destIndex : 3 dest : जानेवारी फेब्रुवारी मार्च एप्रिल मे जून जुलै ऑगस्ट अंतिम गंतव्य अॅरे : जानेवारी फेब्रुवारी मार्च बुधवार जून जुलै ऑगस्ट
पॅरामीटर्स बदलण्याचे उदाहरण
// Example of changing parameters
srcIndex = 4;
destIndex = 5;
len = 1;
आउटपुट
len : 1 srcIndex : 4 src : सोमवार मंगळवार बुधवार गुरुवार शनिवार रविवार गंतव्य निर्देशांक : 5 dest : जानेवारी फेब्रुवारी मार्च एप्रिल मे जून जुलै ऑगस्ट अंतिम गंतव्य अॅरे : जानेवारी फेब्रुवारी मार्च एप्रिल मे शुक्रवार जुलै ऑगस्ट
GO TO FULL VERSION