/** * @author lautturi.com * Java example: Java set the value according to the position in the list */ import java.util.*; public class Lautturi { public static void main(String[] args) { List<Integer> numbers = new ArrayList(Arrays.asList(11,4,2,7,55,16,12,8,13,38)); System.out.println(numbers); // change the 2nd element (index =1); numbers.set(1, 32); System.out.println(numbers); // get the value of 2nd element System.out.println(numbers.get(1)); } }
output:
[11, 4, 2, 7, 55, 16, 12, 8, 13, 38] [11, 32, 2, 7, 55, 16, 12, 8, 13, 38] 32