a liitle bit of program that demonstrates how to add a new entry in a current array that has current values
public class ArraySampleExtendingIndex { private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public static void main(String[] args) throws IOException { boolean insertNew = false, newEntry; int[] numbers = {10, 2}, temp; int length = numbers.length; System.out.print("The Current Values Are: "); System.out.print("["); // display the current values for (int x = 0; x <= numbers.length - 1; x++) { System.out.print(numbers[x]); if (x < numbers.length - 1) { System.out.print(", "); } } System.out.print("]"); System.out.print("\n\n"); do { System.out.print("Add New Entry ? "); String response = br.readLine(); if (response.equalsIgnoreCase("Y")) { System.out.print("Enter Your New Entry: "); int entry = Integer.parseInt(br.readLine()); temp = new int[length]; newEntry = true; // assign the values in the temporary array corresponding to its last position for (int x = 0 ; x <= length - 1; x++) { temp[x] = numbers[x]; } // make an update to the value of the length, dont just add 1 length++; numbers = new int[length]; // add the new entry in the last index for (int i = length - 1; i >= 0; i--) { if (newEntry == true) { numbers[i] = entry; newEntry = false; } else { numbers[i] = temp[i]; } } System.out.print("\n"); System.out.println("New Entry Has Been Added."); System.out.print("\n"); insertNew = true; } else { insertNew = false; } } while (insertNew); System.out.print("\n"); System.out.print("Current Value Are: "); System.out.print("["); // display the array together with the added values for (int x = 0; x <= numbers.length - 1; x++) { System.out.print(numbers[x]); if (x < numbers.length - 1) { System.out.print(", "); } } System.out.print("]"); System.out.print("\n"); } }