Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java copy array

// Shallow copy
int[] src = {1,2,3,4,5};
int[] dst = Arrays.copyOf(src, src.length);

// Deep copy
int[] dst2 = new int[src.length];
for(int i = 0; i < src.length; i++){
	dst2[i] = src[i];
}
Comment

java copy array

int[] a = {1,2,3,4,5};
int[] b = Arrays.copyOf(a, a.length);
Comment

copy array in java

int[] src  = new int[]{1,2,3,4,5};
int[] dest = new int[5];

System.arraycopy( src, 0, dest, 0, src.length );
Comment

copy array in java

public static void arraycopy(Object source_arr, int sourcePos,
                             Object dest_arr, int destPos,
                             int len)
/* Parameters : 
source_arr : array to be copied from
sourcePos : starting position in source array from where to copy
dest_arr : array to be copied in
destPos : starting position in destination array, where to copy in
len : total no. of components to be copied
*/
Comment

how to copy array in java

// method 
public static int [] copyArray(int [] arr){
      int [] copyArr = new int[arr.length];
      for (int i = 0; i < copyArr.length; i++){
            copyArr[i] = arr[i];
       }
      return copyArr;
}

// Arrays. method 
int[] copyCat = Arrays.copyOf(arr, arr.length);

// System 
System.arraycopy(x,0,y,0,5); // 5 is array's length 

// clone 
y = x.clone(); 
Comment

array copy java

// java.util.Arrays.copyOf() method is in java.util.Arrays class.
// It copies the specified array, truncating or padding with false
// (if necessary) so the copy has the specified length.
int[] src = {1,2,3,4};
int[] dst = Arrays.copyOf(src, src.length);

// clone() method.
int[] arrClone = src.clone()
Comment

Copying Arrays Using arraycopy() method Java

arraycopy(Object src, int srcPos,Object dest, int destPos, int length)
Comment

PREVIOUS NEXT
Code Example
Java :: Java List Replace at Index using set() function 
Java :: quick way to get charAt 
Java :: define 2d array in java 
Java :: java max array 
Java :: hashmap declare and initialize with values in 1 line java 
Java :: enhanced for loops 
Java :: can you override static methods in java 
Java :: java recursion 
Java :: java find duplicates in array 
Java :: java lambda 
Java :: java join array 
Java :: java if with string 
Java :: mp3 player java 
Java :: java to c++ converter 
Java :: calling a method in java 
Java :: spring cloud starter eureka client dependency 
Java :: Java Access HashMap Elements 
Java :: Java array repeating 
Java :: Simple Write a simple Java program that prints a staircase or a figure as show 
Java :: jbutton 
Sql :: today minus 15 days postgresql 
Sql :: mysql get table size 
Sql :: wait delay in sql server 
Sql :: list all triggers in sql server 
Sql :: mysql default timestamp value to be current timestamp 
Sql :: mysql unix timestamp to date 
Sql :: sql query to get column data type in sql 
Sql :: sql_mode=only_full_group_by 
Sql :: oracle search source code 
Sql :: group_concat length limit 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =