answersLogoWhite

0

There's a great class called LinkedList that implements the Queue interface. To get an instance of it, use the following code snippet:

import java.util.*;

Queue queue = new LinkedList<T>();

where T is the type of the objects that will go in the queue. Remember the parentheses, as they drove me crazy during one memorable day working out why exactly that same line, minus the parentheses, kept on throwing me a rather unintelligible error.

Example:

Queue<String> q = new java.util.LinkedList<String>()

q.add("a")

q.add("b")

q.add("c")

Calling q.getFirst() returns the value "a".

Likewise, to create a Last-in first out (LIFO) collection, you use a Stack (java.util.Stack).

User Avatar

Wiki User

13y ago

What else can I help you with?

Related Questions

Who create Java and when?

Who create Java &amp; when? Why he create java ? What are mane functions of it?


What the advantages of using the Java Collection Framework?

The main advantage is that you don't have to implement those collections yourself. Java provides very efficient implementations for dozens of collections.


What type of application you can develop in java technology?

You can create games, desktop applications and mobile applications using Java programming language.


What is a java object?

A java object is a collection of methods and properties defined in the Java programming language.


What is a collection of related classes called in java?

a package


Can you initialize an object without constructor in java?

No. if you wish to create an object that you plan on using in a java program then the answer is NO. You cannot initialize an object of a Java class without calling the constructor.


How To write a java program to create three tier applications using servlets?

barsanabegam


2 What is the purpose of garbage collection in java and when is it used?

Garbage collection prevents memory leaks. In Java, the Java Virtual Machine will garbage collect whenever there is memory that has no references.


What is classes in java?

class is a blueprint which does not have its own existence but it can pass all of its feature to its child classes.


How do you create a e-passport website using java swing?

You really don't want to do that. Swing is for desktop applications. If you want to create a website, use Java Server Faces or Applets, not Swing.


Why we can't create a os using java?

Sure, We can design OS using java, c++ and even with C also but the main reason is the code will be very hectic and very lengthy tooo


What is Packages in Java programming?

basically packages are a collection or a directory of similar classes. there are some inbuilt packages in java which prove to be really useful like the java.lang package which automatically is imported into your program. in addition you can also create your own packages and its really simple to create them! :)