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 : সোমবার মঙ্গলবার বুধবার বৃহস্পতিবার শুক্রবার শনিবার রবিবার গন্তব্য সূচক : 3 গন্তব্য : জানুয়ারি ফেব্রুয়ারি মার্চ এপ্রিল মে জুন জুলাই আগস্ট চূড়ান্ত গন্তব্য অ্যারে : জানুয়ারি ফেব্রুয়ারি মার্চ বুধবার জুন জুলাই আগস্ট
পরামিতি পরিবর্তনের উদাহরণ
// Example of changing parameters
srcIndex = 4;
destIndex = 5;
len = 1;
আউটপুট
len : 1 srcIndex : 4 src : সোমবার মঙ্গলবার বুধবার বৃহস্পতিবার শুক্রবার শনিবার রবিবার destIndex : 5 dest : জানুয়ারি ফেব্রুয়ারি মার্চ এপ্রিল মে জুন জুলাই আগস্ট চূড়ান্ত গন্তব্য অ্যারে : জানুয়ারি ফেব্রুয়ারি মার্চ এপ্রিল মে শুক্রবার জুলাই আগস্ট