Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

list of lists java


import java.util.ArrayList;
import java.util.List;
 
public class main {
    public static void main(String[] args){
        List<List<Integer>> lists = new ArrayList<List<Integer>>();
        List<Integer> num1 = Arrays.asList(new Integer[] {1,2,3,4});
        List<Integer> num2 = Arrays.asList(new Integer[] {7,9,3,4});
        lists.add(num1);
        lists.add(num2);
        System.out.println(lists);
    }
}
Comment

list of lists java

List<ArrayList<String>> listOfLists = new ArrayList<ArrayList<String>>();
Comment

list java

    import java.util.*;  
    public class ListExample1{  
    public static void main(String args[]){  
     //Creating a List  
     List<String> list=new ArrayList<String>();  
     //Adding elements in the List  
     list.add("Mango");  
     list.add("Apple");  
     list.add("Banana");  
     list.add("Grapes");  
     //Iterating the List element using for-each loop  
     for(String fruit:list)  
      System.out.println(fruit);  
      
    }  
    }  
Comment

java list

import java.util.*;
var list = new ArrayList<String>();
list.add("Hello World!");
Comment

Java List

// Java Program to illustrate the
// addition of elements in a List
 
import java.util.*;
public class GFG {
 
    public static void main(String args[])
    {
 
        // Creating a List
        List<String> al = new ArrayList<>();
 
        // Adding elements in the List
        al.add("mango");
        al.add("orange");
        al.add("Grapes");
 
        // Iterating the List
        // element using for-each loop
        for (String fruit : al)
            System.out.println(fruit);
    }
}
Comment

list of list in java

// Java code to demonstrate the concept of
// list of lists using iterator
  
import java.util.*;
  
class List_of_list {
  
    // Iterate the 2D list using Iterator
    // and print each element
    public static <K> void
    iterateUsingIterator(List<List<K> > listOfLists)
    {
        // Iterator for the 2D list
        Iterator listOfListsIterator
            = listOfLists.iterator();
  
        System.out.println("[");
        while (listOfListsIterator.hasNext()) {
  
            // Type cast next() method
            // to convert from Object to List<K>
            List<K> list = new ArrayList<K>();
  
            list = (List<K>)listOfListsIterator.next();
  
            // Iterator for list
            Iterator eachListIterator
                = list.iterator();
  
            System.out.print("  [");
            while (eachListIterator.hasNext()) {
  
                System.out.print(
                    "  "
                    + eachListIterator.next()
                    + ", ");
            }
            System.out.println("], ");
        }
        System.out.println("]");
    }
  
    // Driver code
    public static void main(String[] args)
    {
  
        // List of Lists
        ArrayList<List<Integer> > listOfLists
            = new ArrayList<List<Integer> >();
  
        // Create N lists one by one
        // and append to the list of lists
        List<Integer> list1
            = new ArrayList<Integer>();
        list1.add(5);
        list1.add(10);
        listOfLists.add(list1);
  
        List<Integer> list2
            = new ArrayList<Integer>();
        list2.add(1);
        listOfLists.add(list2);
  
        List<Integer> list3
            = new ArrayList<Integer>();
        list3.add(20);
        list3.add(30);
        list3.add(40);
        listOfLists.add(list3);
  
        // Iterate the 2D list
        iterateUsingIterator(listOfLists);
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: java abstract modifier 
Java :: double if statement java 
Java :: object null java 
Java :: Java code to launch shell script with arguments 
Java :: measure view height android 
Java :: java number reverse 
Java :: arrays methods in java 
Java :: merge without extra space 
Java :: Create Java Strings using the new keyword 
Java :: how to find mongo java driver version 
Java :: how to change datatypes in java 
Java :: linear serach in java 
Java :: how to print each element of an arraylist on a new line in java 
Java :: how to skip a line with a filewriter java 
Java :: Java Access superclass attribute 
Java :: java final variable 
Java :: Java Scanner nextInt() 
Java :: room insert and return id 
Java :: list remove duplicates java 
Java :: single level inheritance in java 
Java :: encapsulation in java 
Java :: how do you handle exceptions in java 
Java :: throw exception in spring boot with message and geeter se 
Java :: java map sorted by key 
Java :: java heap example 
Java :: java firebase syncrhonous data read 
Java :: how to install volley java 
Java :: teimpo en segundos java 
Java :: signo zodiaco jaa 
Java :: How to define lambda expression in Java? 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =