And continuing with the Queues the next thing did was making a queue with java API. The thing is Queue is an interface for java. The details in the standard API can be seen here.
As usually did the standard and simplest functions just to get a hang of it.
add(value); for adding elements for the group
always remember in Queue FIFO
remove(); Removes the first in line
peek(); Gives a glance of the first/ head element without removing it
element(); The same as about except in above if the Queue is empty it will return null but in element(); if the Queue is empty it will give an exception.
So as seen here I did implement it using the LinkedList class. following are few of the other known implementing classes.
AbstractQueue, ArrayBlockingQueue, ArrayDeque, ConcurrentLinkedDeque, ConcurrentLinkedQueue, DelayQueue, LinkedBlockingDeque,LinkedBlockingQueue, LinkedList, LinkedTransferQueue, PriorityBlockingQueue, PriorityQueue, SynchronousQueue
As usually did the standard and simplest functions just to get a hang of it.
add(value); for adding elements for the group
always remember in Queue FIFO
remove(); Removes the first in line
peek(); Gives a glance of the first/ head element without removing it
element(); The same as about except in above if the Queue is empty it will return null but in element(); if the Queue is empty it will give an exception.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | import java.util.LinkedList; import java.util.Queue; public class QueueFromAPI { public static void main(String args[]) { Queue A = new LinkedList(); A.add(30); A.add(100); A.add(70); A.add(567); System.out.println("First Element "+ A.element()); A.remove(); // removing one element System.out.println("New First Element " + A.element()); } } |
So as seen here I did implement it using the LinkedList class. following are few of the other known implementing classes.
AbstractQueue, ArrayBlockingQueue, ArrayDeque, ConcurrentLinkedDeque, ConcurrentLinkedQueue, DelayQueue, LinkedBlockingDeque,LinkedBlockingQueue, LinkedList, LinkedTransferQueue, PriorityBlockingQueue, PriorityQueue, SynchronousQueue