Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7590421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:23:49+00:00 2026-05-30T20:23:49+00:00

I want to implement FIFO through a class in Java. Does such a class

  • 0

I want to implement FIFO through a class in Java.

Does such a class already exist? If not, how can I implement my own?

NOTE

I found a class here http://www.dcache.org/manuals/cells/docs/api/dmg/util/Fifo.html, but it doesn’t contain dmg.util.*. I don’t know if such a package even exists.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T20:23:50+00:00Added an answer on May 30, 2026 at 8:23 pm

    You’re looking for any class that implements the Queue interface, excluding PriorityQueue and PriorityBlockingQueue, which do not use a FIFO algorithm.

    Probably a LinkedList using add (adds one to the end) and removeFirst (removes one from the front and returns it) is the easiest one to use.

    For example, here’s a program that uses a LinkedList to queue and retrieve the digits of PI:

    import java.util.LinkedList;
    
    class Test {
        public static void main(String args[]) {
            char arr[] = {3,1,4,1,5,9,2,6,5,3,5,8,9};
            LinkedList<Integer> fifo = new LinkedList<Integer>();
    
            for (int i = 0; i < arr.length; i++)
                fifo.add (new Integer (arr[i]));
    
            System.out.print (fifo.removeFirst() + ".");
            while (! fifo.isEmpty())
                System.out.print (fifo.removeFirst());
            System.out.println();
        }
    } 
    

    Alternatively, if you know you only want to treat it as a queue (without the extra features of a linked list), you can just use the Queue interface itself:

    import java.util.LinkedList;
    import java.util.Queue;
    
    class Test {
        public static void main(String args[]) {
            char arr[] = {3,1,4,1,5,9,2,6,5,3,5,8,9};
            Queue<Integer> fifo = new LinkedList<Integer>();
    
            for (int i = 0; i < arr.length; i++)
                fifo.add (new Integer (arr[i]));
    
            System.out.print (fifo.remove() + ".");
            while (! fifo.isEmpty())
                System.out.print (fifo.remove());
            System.out.println();
        }
    }
    

    This has the advantage of allowing you to replace the underlying concrete class with any class that provides the Queue interface, without having to change the code too much.

    The basic changes are to change the type of fifo to a Queue and to use remove() instead of removeFirst(), the latter being unavailable for the Queue interface.

    Calling isEmpty() is still okay since that belongs to the Collection interface of which Queue is a derivative.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to implement in Java a class for handling graph data structures. I
I want to implement a REST-api in C#. I found that WCF Webapi can
given this class definition: public class Frame { IFrameStream CapturedFrom; } I want implement
I want to implement the replication and fault tolerance in CORBA using Java. I
I wrote small service class and I want implement something like that : service
I want to implement user stories in a new project where can i find
I want implement forward geocoding in my app. But I am not able to
I want implement a program that can do a a Vision-based Page Segmentation. I
I want to implement a generic class AppContextItem with the generic Interface IAppcontextItem. As
I want to implement circular FIFO buffer in C. While I was searching for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.