Menu
Question Index
...

What will be the output of the following program?

import java.util.*;

public class DeleteFromLinkedList
{
    public static void main(String[] args)
    {
        LinkedList<String> lList = new LinkedList<String>();
        lList.add("1");
        lList.add("8");
        lList.add("6");
        lList.add("4");
        lList.add("5");
        System.out.println(lList);
        Collections.sort(lList);
        System.out.println(lList);
        lList.subList(3, 5).clear();
        System.out.println(lList);
        lList.subList(1, 2).clear();
        System.out.println(lList);
    }
}


[1, 8, 6, 4, 5]
[1, 4, 5, 6, 8]
[1, 4, 8]
[1, 8]
[1, 8, 6, 4, 5]
[1, 4, 5, 6, 8]
[1, 4, 5]
[1, 5]
[1, 8, 6, 4, 5]
[1, 4, 5, 6, 8]
[1, 4, 5, 6]
[1, 4, 6]
[1, 8, 6, 4, 5]
[1, 4, 5, 6, 8]
[1, 4, 5, 6, 8]
[1, 4, 5, 6, 8]
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java Collection Algorithms

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App