Question
What are the differences between Queue and Stack in java?

Answers

A collection designed for holding elements prior to processing.
Besides basic Collection operations, queues provide additional insertion, extraction, and inspection operations.

Queues typically, but do not necessarily, order elements in a FIFO (first-in-first-out) manner.
Stack is also a form of Queue but one difference, it is LIFO (last-in-first-out).
Whatever the ordering used, the head of the queue is that element which would be removed by a call to remove() or poll(). Also note that Stack and Vector are both synchronized.

Usage:
Use a queue if you want to process a stream of incoming items in the order that they are received.Good for work lists and handling requests.

Use a stack if you want to push and pop from the top of the stack only. Good for recursive algorithms.   Your Comment




More Software,Java Questions..
What is the inputsplit in map reduce software?

Can variables be used in Java without initialization?

What is the difference between java bean and enterprise java bean?

What is software configuration management?

How does the java database connectivity (jdbc) work?

What are the advantages of threads in java?

What Is Java Api For Xml-based Rpc (jax-rpc)?

How can you implement fine-grained auditing?

What is IBM’s simple explanation for Big Data’s four critical features?

What is static synchronized method in JDBC API? Give an example?

What does the NULLIF function do?

What happens if a start method is not invoked and the run method is directly invoked?

Should we override finalize method

what is the difference between mysql_fetch_array and mysql_fetch_object?

How will XML affect my document links?

What is object cloning in Java?

Why to use Style Sheets?

What are Filters in MVC?

Can you explain Application layer in OSI model?

How to define new testplan attributes?



Search
Can you Answer!!
  • Q A person can move the Supreme Court directly in the event of violation of Fundamental Rights under:
  • Q How is persistence implemented in enterprise beans?
  • Q What Are Other Inline Elements?
  • Q Explain the Ganga and Yamuna action plan
  • Q What are the different job scheduling in operating systems?
  • Q Whats the ultimate cake topping?
  • Q Who was the grandson of Charles Martel?
  • Q What is the difference between a trace value and trace parameters?
  • Q What does hours d'oeurve literally mean
  • Q Tell me does one have to stop other medicines which the patient has been taking?
  • Q Why is it that in some developing countries slum settlements have sprung up near high-rise buildings/wealthier neighbourhoods?