How to iterate over List in List

I am solving a problem. Initially, I have to check what are the elements in this. So, how should I iterate over it????

//Complete the freqQuery function below.
static List<Integer> freqQuery(List<List<Integer>> queries){


2 answers

  • answered 2018-11-08 07:06 Khalid Shah

    static List<Integer> freqQuery(List<List<Integer>> queries) {
                query-> query.forEach(
                             integer->/*do whatever you want*/ )

  • answered 2018-11-08 07:12 Cesare Fischetti

    Use a foreach to take one by one the lists of integer, and, inside it, use another foreach to take all the integers:

    for(List<Integer> lst : queries) {
       for (Integer i : lst) {