Posts

Showing posts with the label copy

Copying array to another array

Sometimes it is required to copy array to another array, how can we do that? Here is the things, In the java.lang.system class we have System.arrayCopy(-,-.....); we can utlize these method to copy the array. Here is the method : System.arraycopy(src, srcPos, dest, destPos, length); Here we have 2 array fields , which we need to copy into the String [] finalfields array. final String [] userField = {"screenName","firstName","lastName","emailAddress","jobTitle"}; final String [] addressFields= {"streetNo","pinCode"}; Calculating the finalfields array size int fieldsSize = userField.length + addressFields.length; String [] finalfields = new String[fieldsSize]; System.arraycopy(userField, 0, finalfields, 0, userField.length); Here we have copied the "userField" array values into the "finalfields" array values. System.arraycopy(addressFields, 0, finalfields, userField.length, addressFie...