Queues in Java

import java.util.Iterator;
import java.util.LinkedList;
import java.util.Queue;

 

public class queuetest {

public void testqueue()
{
Queue<Integer>q=new LinkedList<Integer>();
for(int i=1;i<10;i++)
{
q.add(i);
}

Iterator itr=q.iterator();
for(int i1:q)
{
System.out.println(“Elements of q are”+i1);
}

for(int i=1;i<10;i++)
{
q.remove(i);
}

System.out.println(“Now the elements are”);
if(q.isEmpty())
{
System.out.println(“Queue is Empty”);
}

else
{
for(int i2:q)
{
System.out.println(“Elements of q are”+i2);
}

}
}
public static void main(String cp[])
{
queuetest q1=new queuetest();
q1.testqueue();
}

}

Advertisements

About qainterviews

Software Geek,QA Expert,Blogger
This entry was posted in Java and tagged . Bookmark the permalink.

One Response to Queues in Java

  1. Pingback: Queues in Java « qainterviews

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s