Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth
Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

42,709 questions

55,473 answers

573 users

How to use Array of ArrayLists in Java

1 Answer

0 votes
import java.util.*;
   
public class MyClass {
    public static void main(String args[]) {
        int asize = 4;
        
        ArrayList<Integer>[] al = new ArrayList[asize]; 
  
        for (int i = 0; i < asize; i++) { 
            al[i] = new ArrayList<Integer>(); 
        } 
        
        al[0].add(1); 
        al[0].add(2); 
        al[0].add(3); 

        al[1].add(4); 
        al[1].add(5); 

        al[2].add(6); 
        al[2].add(7); 
        al[2].add(8); 
        al[2].add(9); 

        al[3].add(78); 
        al[3].add(99); 
        al[3].add(100); 
        al[3].add(89); 
        al[3].add(90); 

        for (int i = 0; i < asize; i++) { 
            for (int j = 0; j < al[i].size(); j++) { 
                System.out.print(al[i].get(j) + " "); 
            } 
            System.out.println(); 
        }  
    }
}
   
   
   
   
/*
run:
   
1 2 3 
4 5 
6 7 8 9 
78 99 100 89 90 
   
*/

 



answered Apr 22, 2020 by avibootz

Related questions

2 answers 198 views
1 answer 165 views
1 answer 210 views
1 answer 219 views
1 answer 176 views
176 views asked Apr 21, 2020 by avibootz
...