Write a Java 8 program to get the last element of an array string/object
Categories: Java 9 Java 8(JDK1.8) Java Java Examples
package r4r.co.in;
import java.util.stream.Stream;
public class LastElementOfAnArray {
public static void main(String[] args) {
//Write a Java 8 program to get the last element of an array string/object
String[] input = { "Rajesh", "Kumar", "Verma", "R4R" };
String lastElement = Stream.of(input).skip(input.length - 1).findAny().get();
System.out.println(lastElement);
}
}
Output :R4R