Skip to content

Instantly share code, notes, and snippets.

@edinak1
Created November 3, 2015 20:03
Show Gist options
  • Save edinak1/1dcf8d500a4ae1bca17a to your computer and use it in GitHub Desktop.
Save edinak1/1dcf8d500a4ae1bca17a to your computer and use it in GitHub Desktop.
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++];
}
}
}
@liuiv15
Copy link

liuiv15 commented Nov 16, 2015

А если случайно передать значение индексов отрицательными, что будет?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment