Menu
Question Index
...

Write a program to get last element from the list.

Input (Integer List) Output (Integer)
[14, 15, 21] 21
[45, 67, 89, 25] 25
[887] 887
[] null
null null


import java.util.*;
class GetLastElementInList
{
    public static void main(String s[])
    {
        ArrayList<Integer> list = new ArrayList<Integer>();
        list.add(12);
        list.add(33);
        list.add(45);
        list.add(55);
        System.out.println("The last element in the list [12, 33, 45, 55] is " + getLastElement(list));

    }


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

}

Doubts

Problems

Topic: Java ArrayList

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App