import java.util.Arrays;
import java.util.List;
public class Test {
public static void main(String[] args) {
List list = Arrays.asList("node", "java", "c++", "react", "javascript");
Object result = list.get(list.size() - 1);
System.out.println(result);
Object result2 = list.stream().skip(list.size() - 1).findFirst().orElse("no last element");
System.out.println(result2);
Object result3 = list.stream().reduce((first, second) -> second).orElse("no last element");
System.out.println(result3);
}
// 同样也可以适用于list<Object>的取值
输出
javascript
javascript
javascript