Java Program to Insert Element At the End of Array

In this tutorial, we will learn writing Java Program to insert an element at the end of an array and print the array. Our program will add an element at the end of the given array (list).

For example

Case 1: if the given array is {1, 2, 3, 4} and the users give input 9 to add at last.

           The output should be {1, 2, 3, 4, 9}.

Case 2: if the given array is {9, 2, 4, 8} and the users give input 10 to add at last.

           The output should be {9, 2, 4, 8, 10}.

Java Program to Insert Element At the End of Array

Output

Java Program to Insert Element At the End of Array

Explanation

For the given array {1, 2, 3, 4, 5 }, the user inputs element 6 to add at the end of the array. Using the arr[size] method, our program will easily add element 6 at the end of the list and returns the updated list.