▪️GetTheLastStoredValue.java
import java.util.*;
public class GetTheLastStoredValue {
public static void main(String[] args) {
List<Integer> numbers = new ArrayList<Integer>();
numbers.add(5);
numbers.add(100);
numbers.add(9);
numbers.add(4);
numbers.add(50);
// acquire the last value stored away by a list
System.out.println(numbers.get(numbers.size() - 1));
// acquire the value of the last but one(最後から2番目の値を取得する)
System.out.println(numbers.get(numbers.size() - 2));
System.out.println(numbers.get(numbers.size() - 3));
}
}
▪️実行結果
50
4
9