i'm doing some practice in Arrays using Intellij idea first time, But it's giving me this errors:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at ArrayDemo.main(ArrayDemo.java:6)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Why i'm getting this, will anyone please tell me the reason?
here is my program:
public class ArrayDemo{
public static void main(String[] args){
char[] copyFrom={'a', 'b', 'c', 'e', 'f', 'g', 'g'};
char[] copyTo=new char[7];
System.arraycopy(copyFrom, 2, copyTo, 0, 7);
System.out.println(new String(copyTo));
}
}