answersLogoWhite

0

How do you create a FIFO collection using Java?

Updated: 8/19/2019
User Avatar

Wiki User

12y ago

Best Answer

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

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you create a FIFO collection using Java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Who create Java and when?

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


What type of application you can develop in java technology?

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


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.


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

barsanabegam


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 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.


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.


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


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! :)


Can you create a constructor for an interface in java?

NO, we cannot create a contructor for an interface in java.