Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

arraylist of arraylist

public static void main(String[] args) {
    ArrayList<ArrayList<Integer>> outer = new ArrayList<ArrayList<Integer>>();
    ArrayList<Integer> inner = new ArrayList<Integer>();        

    inner.add(100);     
    inner.add(200);
    outer.add(inner); // add first list
    inner = new ArrayList<Integer>(inner); // create a new inner list that has the same content as  
                                           // the original inner list
    outer.add(inner); // add second list

    outer.get(0).add(300); // changes only the first inner list

    System.out.println(outer);
}
Comment

array arraylist java

// Create
String[] myArray = {"A", "B", "C"};
// constructor no.3, passing a collection
List<String> myArrayList = new ArrayList<>(Arrays.asList("A", "B", "C"));
// Get element
String i = myArray[1];
String j = myArrayList.get(1);
// Get size
int k = myArray.length;     // length is a public field in array, not method.
int l = myArrayList.size();
// Add an element, you can't that w/ array as it is fixed in length
myArrayList.add("D");
// Set an element
myArray[0] = "E";
myArrayList.set(0, "E");
// Remove an element, can't w/ array b/c fixed length
myArrayList.remove(2);  // remove by index
myArrayList.remove("E");    // remove by object
Comment

arraylist of arraylist


public static void main(String[] args) {
    ArrayList<ArrayList<Integer>> outer = new ArrayList<ArrayList<Integer>>();
    ArrayList<Integer> inner = new ArrayList<Integer>();        

    inner.add(100);     
    inner.add(200);
    outer.add(inner); // add first list
    inner = new ArrayList<Integer>(inner); // create a new inner list that has the same content as  
                                           // the original inner list
    outer.add(inner); // add second list

    outer.get(0).add(300); // changes only the first inner list

    System.out.println(outer);
}

Comment

how to create Java ArrayList

// welcome to softhunt.net
import java.util.ArrayList;

class Main {
  public static void main(String[] args){

    // create ArrayList
    ArrayList<String> Websites = new ArrayList<>();

    // Add elements to ArrayList
    Websites.add("Softhunt.net");
    Websites.add("Pythonprogramming.com");
    Websites.add("Tutorial.io");
    System.out.println("ArrayList: " + Websites);
  }
}
Comment

array of arraylist in java

// Java code to demonstrate the concept of 
// array of ArrayList
  
import java.util.*;
public class Arraylist {
    public static void main(String[] args)
    {
        int n = 5;
  
        // Here al is an array of arraylist having
        // n number of rows.The number of columns on
        // each row depends on the user.
        // al[i].size() will give the size of the
        // i'th row
        ArrayList<Integer>[] al = new ArrayList[n];
  
        // initializing
        for (int i = 0; i < n; i++) {
            al[i] = new ArrayList<Integer>();
        }
  
        // We can add any number of columns to each
        // rows as per our wish
        al[0].add(1);
        al[0].add(2);
        al[1].add(5);
        al[2].add(10);
        al[2].add(20);
        al[2].add(30);
        al[3].add(56);
        al[4].add(34);
        al[4].add(67);
        al[4].add(89);
        al[4].add(12);
  
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < al[i].size(); j++) {
                System.out.print(al[i].get(j) + " ");
            }
            System.out.println();
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: sending a excel in an attachment in email java 
Java :: how to find a word in a statement java 
Java :: linear serach in java 
Java :: what is the max size of array in java 
Java :: index 1 out of bound for length 1 java 
Java :: java int 0/0 
Java :: java arraylist initialize with 0 
Java :: resttemplate get rest api call in java 
Java :: Java List Remove Elements using remove() method 
Java :: java change hashmap value 
Java :: Java Access Array Elements 
Java :: for() in java 
Java :: next line java does not take input 
Java :: java data structure 
Java :: unresolved reference activity_main 
Java :: switch statement in java 
Java :: java startswith regex 
Java :: splash full screen android 
Java :: java decler variabel 
Java :: array buffer 
Java :: android studio tabbed activity 
Java :: |= java operation 
Java :: java firebase syncrhonous data read 
Java :: Method Overloading by changing the data type of parameters Java 
Java :: natural log in java 
Java :: generate random color java 
Java :: android system navigation back bar hide 
Java :: gson to class 
Java :: javacal 
Java :: return string consistent of n lowercase letters such is all letters occurs an odd number 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =