Create an ArrayList with multiple object types?

前端 未结 12 2584
抹茶落季
抹茶落季 2020-12-08 01:57

How do I create an ArrayList with integer and string input types? If I create one as:

List sections = new ArrayList 

        
12条回答
  •  感动是毒
    2020-12-08 02:40

    (1)

       ArrayList list = new ArrayList <>();`     
       list.add("ffffd");
       list.add(2);
       list.add(11122.33);    
       System.out.println(list);
    
    
    

    (2)

     ArrayList arraylist = new ArrayList();
     arraylist.add(5);        
     arraylist.add("saman");     
     arraylist.add(4.3);        
     System.out.println(arraylist);
    

    提交回复
    热议问题