Menu
Question Index
...

Write a program to get the first element from given input using one of the Queue interface methods.
Note the elements in Queue by default sorted in ascending order.

Input (Queue) Output (String)
[Lion, Tiger, Cat, Rabbit, Mouse] Cat
[Suman, Sekhar, Rohan, Sukumar, Praneeth, Prakash] Prakash
[Kalyan, Kishore, Ashok, Revanth, Sashi] Ashok
null null


import java.util.*;
class GetFirstElement
{
    public static void main(String s[])
    {
        PriorityQueue<String> input = new PriorityQueue<String>();
        input.add("Ramesh");
        input.add("Sujan");
        input.add("Ravi");
        input.add("Ramu");
        input.add("Krishna");
        System.out.println("The first element is: " + getFirstElelment(input));

    }


    public static String getFirstElelment(Queue<String> input) {
    }

}

Doubts

Problems

Topic: Java ArrayDeque Class

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App