The first element

Report a typo

Define and implement a generic static method getFirst that returns the first element of an input array or null in case the array is empty.

The use-case of the method for an integer array:

int[] array = new int[10, 6, 2, 3];
int first = getFirst(array); // 10

Sample Input 1:

Integer
10 6 2 3

Sample Output 1:

10
Write a program in Java 17
// do not remove imports
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.function.Function;

class ArrayUtils {
// define getFirst method here
}
___

Create a free account to access the full topic