Welcome To The World Of Hacking


Learn Hacking|Teach Hacking|Learn To Secure|Learn To Code

Sunday

JAVA PROGRAMMING TUTORIAL 39 : QUEUE

//A Queue is a first-in, first-out(FIFO) data structure
//The offer method inserts an element
//The peek() methods return the head of the queue
//The poll() methods remove the head of the queue

import java.util.*;

public class HackDefence{

public static void main(String[] args){

            PriorityQueue<String> q = new PriorityQueue<String>();
 
            q.offer("First");
 
            q.offer("Second");
 
            q.offer("Third");
 
            System.out.printf("%s",q);
 
            System.out.println();
 
            System.out.printf("%s", q.peek());
 
            System.out.println();
 
            q.poll();
 
            System.out.printf("%s", q);
 
}

}

OUTPUT:

1 comment:

Related Posts Plugin for WordPress, Blogger...