import java.util.Arrays;
public class Main {
public static void main(String[] args) {
String[] seasons = new String[] {"Winter", "Spring", "Summer", "Autumn"};
seasons = addElementToFront(seasons, "Hell");
seasons = addElementToFront(seasons, "Hell2");
System.out.println(Arrays.toString(seasons));
}
public static String[] addElementToFront(String[] arr, String element) {
String[] newArr = new String[arr.length + 1];
newArr[0] = element;
System.arraycopy(arr, 0, newArr, 1, arr.length);
return newArr;
}
}
import java.util.Arrays;
public class Test {
public static void main(String[] args) {
Integer[] ints = new Integer[]{1, 2, 3, 4, 5, 6};
System.out.println(Arrays.toString(add(ints, 0)));
}
private static T[] add(T[] original, T value) {
T[] copy = (T[]) new Object[original.length + 1];
System.arraycopy(original, 0, copy, 1, original.length);
copy[0] = value;
return copy;
}
}