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>();
        System.out.println("The first element is: " + getFirstElelment(input));


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




Topic: Java ArrayDeque Class

Read this topic
Take test on this topic

Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App