I can't initialize it.

ArrayList<Queue<Pair>> colors = new ArrayList<Queue<Pair>>(); colors.ensureCapacity(l+1); colors.get(0).add(new Pair(1, 1, 0)); 

Swears on the last line

    1 answer 1

    You request the first element, which is not present, and you try to call the add method from it.

    Something like this:

     import java.util.ArrayList; import java.util.LinkedList; import java.util.Queue; ... static class Pair { public Pair(int a, int b, int c) {} } ... ArrayList<Queue<Pair>> colors = new ArrayList<Queue<Pair>>(); colors.add(new LinkedList()); colors.get(0).add(new Pair(1, 1, 0)); 

    Queue is an interface, so you cannot create its objects, but you need to use classes that implement this interface.

    • and how to announce them. Can you give an example, please? - P.Star