Create an ArrayList with multiple object types?

前端 未结 12 2586
抹茶落季
抹茶落季 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:45

    You don't know the type is Integer or String then you no need Generic. Go With old style.

    List list= new ArrayList ();
    
    list.add(1);
    list.add("myname");
    
    for(Object o = list){
    
    } 
    

提交回复
热议问题