Search code examples
javaqueuecall

How to make a call on static method with queue


// I want to pass [1, 2, 3, 4, 5, 6] into mystery2 //

public static void main(String[] args) {
    mystery2(1, 2, 3, 4, 5, 6); // need help here
}

public static void mystery2(Queue<Integer> q) {    
}

Solution

  • You can pass like this..

    mystery2(new LinkedList<>(Arrays.asList(1,2,3,4,5,6)); 
    

    LinkedList implements Queue interface and has the Constructor that takes the Collection as an constructor argument.

    Hope this helps. Cheers !!!