Create an ArrayList with multiple object types?

前端 未结 12 2585
抹茶落季
抹茶落季 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条回答
  •  猫巷女王i
    2020-12-08 02:30

    Just use Entry (as in java.util.Map.Entry) as the list type, and populate it using (java.util.AbstractMap’s) SimpleImmutableEntry:

    List> sections = new ArrayList<>();
    sections.add(new SimpleImmutableEntry<>(anInteger, orString)):
    

提交回复
热议问题