Use set method to change the value in an array list in Java
Description
The following code shows how to use set method to change the value in an array list.
Example
/*from w w w. j ava 2 s . com*/
import java.util.ArrayList;
public class Main {
public static void main(String[] a) {
ArrayList<String> nums = new ArrayList<String>();
nums.clear();
nums.add("One");
nums.add("Two");
nums.add("Three");
System.out.println(nums);
nums.set(0, "Uno");
nums.set(1, "Dos");
nums.set(2, "java2s.com");
System.out.println(nums);
}
}
The code above generates the following result.