1import java.util.ArrayList;
2import java.util.Arrays;
3import java.util.List;
4
5class Main
6{
7 private static Integer[] append(Integer[] arr, int element) {
8 List<Integer> list = new ArrayList<>(Arrays.asList(arr));
9 list.add(element);
10
11 return list.toArray(new Integer[0]);
12 }
13
14 public static void main(String[] args) {
15
16 Integer[] nums = { 1, 2, 3, 4 };
17
18 nums = append(nums, 5); // add 5 to nums[]
19 System.out.println(Arrays.toString(nums));
20 }
21}
22