append to araray java code example
Example: how to append to an array in java
import java.util.Arrays;
class ArrayAppend {
public static void main( String args[] ) {
int[] arr = { 10, 20, 30 };
System.out.println(Arrays.toString(arr));
arr = Arrays.copyOf(arr, arr.length + 1);
arr[arr.length - 1] = 40; // Assign 40 to the last element
System.out.println(Arrays.toString(arr));
}
}