To change the value of an element in an array in Java SE 22, you simply access the element by its index and assign a new value to it. Here’s an example:
public class Main { public static void main(String[] args) { // Create an array of integers int[] numbers = {1, 2, 3, 4, 5}; // Change the value of the third element (index 2) to 10 numbers[2] = 10; // Print the modified array for (int number : numbers) { System.out.println(number); } } }
In this example, `numbers[2] = 10;` changes the value of the third element (index 2) in the array `numbers` to 10. You can replace `10` with any value of the appropriate type for the array.