Skip to content

Instantly share code, notes, and snippets.

@edinak1
Created November 3, 2015 20:02
Show Gist options
  • Save edinak1/3e0a80f2cecce05d79af to your computer and use it in GitHub Desktop.
Save edinak1/3e0a80f2cecce05d79af to your computer and use it in GitHub Desktop.
Copy.java
package test;
import java.util.Arrays;
public class Copy {
public static void main(String[] args) {
int []src={1,2,3};
int []dest={0,7,9,8,34};
copyArray(src,0,dest,0,3);
System.out.println(Arrays.toString(dest));;
}
static void copyArray(int[]src,int srcPos, int[]dest, int destPos,int length)
{
if(src==null || dest == null || srcPos>src.length-1 ||
src.length<length || dest.length<(destPos+length))
{
System.out.println("arguments not correct, arrays don't change");
return;
}
for(int i=destPos;i<destPos+length;i++)
{
dest[i]= src[srcPos++];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment