I have a class InQueue with the following:
static Queue<String> q = null;
public InQueue(String[] input){
q = new LinkedList<String>();
}
public static Queue<String> newInputQueue(String[] inputArray){
q.addAll(Arrays.asList(inputArray));
q.add("$");
return q;
}
And I have an array in main that I'm trying to do this:
String[] inputArr = {"id", "+", "id", "*", "id"};
InQueue inQueue = new InQueue(inputArr);
I want to pass inputArr to inQueue so that my array goes into the queue. But obviously I can't do that because the InQueue constructor doesn't have parameters. Is there a way to do this? I've tried various ways and most of them either don't work, or they return an empty queue.
q, andqbeing static means you can only ever have a single instance ofqat any given time. If you made a new empty queue after the fact, it'd overwrite/erase any other queues to begin with. That's why you shouldn't usestatichere, particularly for a (design-wise) instance variable.