java how to change the size of an array code example
Example 1: how to replace an element in array in java
class array{
public static void main(String[] args){
int arr[] = {1,2,3,4};
System.out.println("Before update" + arr[2]);
arr[2] = 9;
System.out.println("After update" + arr[2]);
}
}
Example 2: .length array java
public class ArrayLengthJava {
public static void main(String[] args) {
String[] myArray = { "I", "Love", "Music" };
int arrayLength = myArray.length;
System.out.println("The length of the array is: " + arrayLength);
}
}