ObjectUtils.javaspring-core/src/main/java/org/springframework/util
1public static <A, O extends A> A[] addObjectToArray(A @Nullable [] array, O obj, int position) {
2 Class<?> = Object.class;
3 if (array != null) {
4 = array.getClass().();
5 }
6
7 else if (obj != null) {
8 = obj.getClass();
9 }
10 int newArrayLength = (array != null ? array.length + 1 : 1);
11 @SuppressWarnings("unchecked")
12 A[] newArray = (A[]) Array.newInstance(, newArrayLength);
13 if (array != null) {
14 System.arraycopy(array, 0, newArray, 0, position);
15 System.arraycopy(array, position, newArray, position + 1, array.length - position);
16 }
17 newArray[position] = obj;
18 return newArray;
19}