简体   繁体   中英

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){

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

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) {
       System.out.println(i);
    } 
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM