Java.lang.System.arraycopy() Method - Tutorialspoint

文章推薦指數: 80 %
投票人數:10人

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



請為這篇文章評分?