0
我有多个集合,我想将它们全部添加到数组或其他集合中,以便我可以使用索引访问它们。我创建了一个LinkedHashMap并将它们存储在那里。如何存储多个集合以通过索引访问
static HashSet <Passenger> floor1 = new HashSet<Passenger>();
static HashSet <Passenger> floor2 = new HashSet<Passenger>();
static HashSet <Passenger> floor3 = new HashSet<Passenger>();
static LinkedHashMap floors = new LinkedHashMap(); //what will be the type for this?
public static void main (String[]argv) {
floors.put(1,floor1);
floors.put(2,floor2);
floors.put(3,floor3);
}
现在,如果我要访问这个集合中的一个,并在其中添加一些东西,它不会让我在里面添加任何东西。
floors.get(2).add(1); //this add function does not work
什么是堆叠集合的最佳方式是什么?
感谢您提前给予您所有的帮助。
请勿使用原始类型。 –