Get last but one element - Java Quiz Question


Write a program to get the last but one element.

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


import java.util.*;
class GetLastButOneElement
{
    public static void main(String s[])
    {
        ArrayList<Integer> list = new ArrayList<Integer>();
        list.add(12);
        list.add(34);
        list.add(77);
        list.add(56);
        System.out.println("The last but one element in list [12, 34, 77, 56] is " + getLastButOneElement(list));

    }


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

}