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

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,855 questions

51,776 answers

573 users

How to get rows and columns of dynamic 2D ArrayList in java

1 Answer

0 votes
import java.util.ArrayList;
import java.util.List;

public class MyClass {
    public static void main(String args[]) {
        List<int[]> li = new ArrayList<>();
        
        li.add(new int[]{6, 8, 1, 2});
        li.add(new int[]{9, 3, 4});
        li.add(new int[]{5, 7});
        
        System.out.printf("total rows: %d\n", li.size()); 
        
        for (int i = 0; i < li.size(); i++) {
            System.out.printf("row: %d - cols: %d\n", i, li.get(i).length); 
        }   
    }
}
 
 
 
/*
run:
 
total rows: 3
row: 0 - cols: 4
row: 1 - cols: 3
row: 2 - cols: 2
 
*/

 



answered Mar 22, 2021 by avibootz

Related questions

1 answer 186 views
1 answer 164 views
1 answer 163 views
163 views asked Mar 22, 2021 by avibootz
3 answers 212 views
212 views asked Mar 22, 2021 by avibootz
2 answers 119 views
...