Create an array of ArrayList elements

后端 未结 12 1929
遥遥无期
遥遥无期 2020-12-03 01:27

I want to create an array that contains ArrayList elements.

I\'ve tried

ArrayList name[] = new ArrayList()[];
         


        
12条回答
  •  渐次进展
    2020-12-03 01:30

    I have tried this without an error, even though I have putted a limit in the array less than the amount of items added:

    package Testes.src;
    
    import java.util.ArrayList;
    import java.util.List;
    
    public class Testes {
    
        private List name=new ArrayList(1);
    
        public Testes(){
            for (int i = 1; i <= 100; i++) {
                name.add("Teste"+Integer.toString(i));
            }
            for (int i = 0; i < name.size(); i++) {
                System.out.println(name.get(i));
            }
        }
        public static void main(String [] args)
        {
            Testes t1=new Testes();
        }
    }
    

提交回复
热议问题