how to create an 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();
}
}
}
ArrayList<String> a = new ArrayList<>( Arrays.asList(oldArray));
Also in Java:
- Please ensure that your JAVA_HOME points to a valid Java SDK. You are currently pointing to: /usr/lib/jvm/java-13-oracle
- java variables in annotations
- how to create a linked list in java
- java array to list
- java - a program to print open ports
- if statement java
- java call another constructor
- java 8 collect multiple lists into single list
- java pass array as method parameter
- python vs java
- java read from connection even if 404
- spigot repeating task
- how to add an object to a list of objects in java
- java square a number
- fragment button nullpointerexception
- how to get all the names of the files in a folder in java?
- java stream to list
- print hello world in java
- arraylist with values java
- foreach map java
- java stream sorted reverse
- java get icon for file type
- how to create an array of arraylist in java
- convert string to int java