Java.lang.System.arraycopy() Method - Tutorialspoint
文章推薦指數: 80 %
The java.lang.System.arraycopy() method copies an array from the specified source array, beginning at the specified position, to the specified position of ... Home CodingGround Jobs Whiteboard Tools Business Teachwithus Java.langPackageclasses Java.lang-Home Java.lang-Boolean Java.lang-Byte Java.lang-Character Java.lang-Character.Subset Java.lang-Character.UnicodeBlock Java.lang-Class Java.lang-ClassLoader Java.lang-Compiler Java.lang-Double Java.lang-Enum Java.lang-Float Java.lang-InheritableThreadLocal Java.lang-Integer Java.lang-Long Java.lang-Math Java.lang-Number Java.lang-Object Java.lang-Package Java.lang-Process Java.lang-ProcessBuilder Java.lang-Runtime Java.lang-RuntimePermission Java.lang-SecurityManager Java.lang-Short Java.lang-StackTraceElement Java.lang-StrictMath Java.lang-String Java.lang-StringBuffer Java.lang-StringBuilder Java.lang-System Java.lang-Thread Java.lang-ThreadGroup Java.lang-ThreadLocal Java.lang-Throwable Java.lang-Void Java.langPackageextras Java.lang-Interfaces Java.lang-Errors Java.lang-Exceptions Java.langPackageUsefulResources Java.lang-UsefulResources Java.lang-Discussion SelectedReading UPSCIASExamsNotes Developer'sBestPractices QuestionsandAnswers EffectiveResumeWriting HRInterviewQuestions ComputerGlossary WhoisWho Java.lang.System.arraycopy()Method Advertisements PreviousPage NextPage CompleteJavaProgrammingFundamentalsWithSampleProjects 98Lectures 7.5hours EmenwaGlobal,EjikeIfeanyiChukwu MoreDetail GetyourJavadreamjob!Beginnersinterviewpreparation 85Lectures 6hours YuvalIshay MoreDetail CoreJavabootcampprogramwithHandsonpractice Featured 99Lectures 17hours PrashantMishra MoreDetail Description Thejava.lang.System.arraycopy()methodcopiesanarrayfromthespecifiedsourcearray,beginningatthespecifiedposition,tothespecifiedpositionofthedestinationarray.Asubsequenceofarraycomponentsarecopiedfromthesourcearrayreferencedbysrctothedestinationarrayreferencedbydest.Thenumberofcomponentscopiedisequaltothelengthargument. ThecomponentsatpositionssrcPosthroughsrcPos+length-1inthesourcearrayarecopiedintopositionsdestPosthroughdestPos+length-1,respectively,ofthedestinationarray. Declaration Followingisthedeclarationforjava.lang.System.arraycopy()method publicstaticvoidarraycopy(Objectsrc,intsrcPos,Objectdest,intdestPos,intlength) Parameters src−Thisisthesourcearray. srcPos−Thisisthestartingpositioninthesourcearray. dest−Thisisthedestinationarray. destPos−Thisisthestartingpositioninthedestinationdata. length−Thisisthenumberofarrayelementstobecopied. ReturnValue Thismethoddoesnotreturnanyvalue. Exception IndexOutOfBoundsException−ifcopyingwouldcauseaccessofdataoutsidearraybounds. ArrayStoreException−ifanelementinthesrcarraycouldnotbestoredintothedestarraybecauseofatypemismatch. NullPointerException−ifeithersrcordestisnull. Example Thefollowingexampleshowstheusageofjava.lang.System.arraycopy()method. LiveDemo packagecom.tutorialspoint; importjava.lang.*; publicclassSystemDemo{ publicstaticvoidmain(String[]args){ intarr1[]={0,1,2,3,4,5}; intarr2[]={5,10,20,30,40,50}; //copiesanarrayfromthespecifiedsourcearray System.arraycopy(arr1,0,arr2,0,1); System.out.print("array2="); System.out.print(arr2[0]+""); System.out.print(arr2[1]+""); System.out.print(arr2[2]+""); System.out.print(arr2[3]+""); System.out.print(arr2[4]+""); } } Letuscompileandruntheaboveprogram,thiswillproducethefollowingresult− array2=010203040 java_lang_system.htm PreviousPage PrintPage NextPage Advertisements
延伸文章資訊
- 1How To Copy / Clone An Array In Java - Software Testing Help
You can use a for loop and copy elements of one to another one by one. Use the clone method to cl...
- 2java.lang.System.arraycopy()方法實例 - 極客書
java.lang.System.arraycopy() 方法複製從指定源數組的數組,開始在指定的位置, ... public static void arraycopy(Object src,...
- 3Make copy of an array - java - Stack Overflow
Object.clone(): Object class provides clone() method and since array in java is also an Object, y...
- 4在Java 中複製陣列| D棧 - Delft Stack
javaCopy import java.util.Arrays; public class CopyArray { public static void main(String[] args)...
- 5Array Copy in Java - GeeksforGeeks
clone() creates a new array of the same size, but System.arraycopy() can be used to copy from a s...