1class array{
2 public static void main(String[] args){
3 int arr[] = {1,2,3,4};
4 System.out.println("Before update" + arr[2]);
5 arr[2] = 9;//updating the value
6 System.out.println("After update" + arr[2]);
7 }
8}
9
10/*output:-
11Before update3
12After update9*/
1list.set(1,"new value");
2
3//example ..
4
5List<String> list = new ArrayList<>();
6list.add("one");
7list.add("two");
8list.add("three");
9System.out.println(list); // [one,two,three]
10list.set(1,"new");
11System.out.println(list); //[one,new,three]