Erez Shmiel Erez Shmiel - 28 days ago 7
Android Question

How to add an object to pair of pair list in java?

the list type:

List<Pair<Integer, Pair<Integer, Integer>>> listPairOfPair = null;


I tried these but it didn't work:

listPairOfPair.add(new Pair<Integer, Pair<Integer, Integer>>(1, (2,3));

listPairOfPair.add(new Pair<Integer, Pair<Integer, Integer>>(1, Pair.create(2,3)));

Answer

Unfortunately, there is no "nice" syntax to do that. You need to go level by level:

Pair<Integer, Integer> onePair = new Pair<>(1, 2); // assuming that you got such a constructor there!

Pair<Integer, Pair<Integer, Integer>> listOfPair = new ArrayList<>();
listOfPair.add(onePair);

List<Pair<Integer, Pair<Integer, Integer>>> listPairOfPair = new ArrayList<>();
listPairOfPair.add(listOfPair);
Comments