Search code examples
javalinked-listintegerqueuedeque

Is it possible to assign numbers to strings and then put those numbers in a dequeue system?


I'm writing some code and I would like some help with an issue to do with queue's in Eclipse. Is there any way to assign numbers to a string of characters and then put those numbers in a dequeue system whereby the end function will tell the user the string of characters not the number and leave the head of the queue ? I have tried multiple different iterations using de_queue but nothing has seemed to work so far.Sorry if this may seem basic, I haven't had Java long. This is what the code looks like now but i understand the format will need altering. Any help is appreciated.

package britishairways;

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

public class Crew {

    public static void main(String[] args) {

        Queue<String> crewLine = new LinkedList<String>();

        crewLine.add("Sam and Rick");
        crewLine.add("Beth and Mark");
        crewLine.add("Jennifer and Chris");
        crewLine.add("Akshay and Ahmed");
        crewLine.add("Nick and Heather");

        System.out.println(crewLine.poll());
        System.out.println(crewLine);
     }
 }

Solution

  • Maybe try to use a help class like.

    public class LineElement{
         private String names;
         private int id;
         public LineElement(int id, String names){
             this.id = id;
             this.names = names;
         }   
    }
    

    and then init the Queue like: Queue<LineElement> crewLine = new LinkedList<LineElement>(); and add new Elements with: crewLine.add(new LineElement(14, "Morthie and ick"));