Get first element from list - Java Quiz Question


Write a program to get first element from the input Integer list.

Input (Integer List) Output (Integer)
[14, 15, 21] 14
[23, 45, 67, 89, 25, 33, 55] 23
[124] 124
[] null
null null


import java.util.*;
class GetFirstElementInList
{
    public static void main(String s[])
    {
        ArrayList<Integer> list = new ArrayList<Integer>();
        list.add(23);
        list.add(45);
        list.add(67);
        list.add(89);
        list.add(25);
        list.add(33);
        list.add(55);
        System.out.println("The first element of list [23, 45, 67, 89, 25, 33, 55] is : " + getFirstElement(list));

    }


    public static Integer getFirstElement(List<Integer> list)
    {
             Integer result = null;
             return result;
    }

}