dcsimg
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Java
Expertise: Intermediate
Oct 24, 2003

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Copy One Array to Another Without Using Loops or Conditions

Here's the code the usage of arraycopy:

public class testarrcopy
{
 public static void main(String arg[])
 {
   //Array of any object can be user defined object
   String source[] =
{"one","two","thr","four","five","six","sev","eight","nine","ten"};

   //Array of any object can be user defined object
   String dest[] = new String[5];


   ...some conditions or calculations..

   /*
    *This method copies source array to destination Array.
    *It starts copy from the position 3 from source array.
    *If we didn't properly set the values to the function it may leads to
the exceptions like     *IndexOutOfBoundsException
,ArrayStoreException,NullPointerException
    */
   System.arraycopy(source,3,dest,0,5);

   //the following loop tests the values in the dest array
   for(int i=0; i< dest.length; i++)
     System.out.println(dest[i]);

 }
}
Elayaraja David
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date