I need to make a class for working with arrays with static generic methods. For example in this function I need to paste one array(arr2) inside other(arr1) at some index (place).
public static<T> void paste(T[] arr1, int place, T[] arr2) {
Object[] temp = new Object[arr1.length + arr2.length];
System.arraycopy(arr1, 0, temp, 0, place);
System.arraycopy(arr2, 0, temp, place, arr2.length);
System.arraycopy(arr1, place, temp, place+arr2.length, arr1.length-place);
arr1 = (T[])temp;
}
The function work correctly, but I cant see changes in main function. The result always remains in paste function. What can I do in this situation?
public static void main(String[] args) {
Integer arr[] = {1 ,2 ,3 ,4, 5};
Integer arr2[] = {11 ,22 ,33 ,44, 55};
paste(arr, 2, arr2);
show(arr);
}