java - How to manage array/arraylist of queues/LinkedLists? -
i realize queue interface. problem this. have queue initialized linkedlist each day of month (31) , need arrange them. having issues understanding issues generics. first idea either make array of queues (java doesn't seem this). or should make arraylist of type queue , make initial size 32?
if that, how reference specific queue add it? this?:
for i'll i'm trying add list 17th day.
arraylist<queue<passenger>> lists = new arraylist<queue<passenger>>(32); passenger person = new passenger(first, last); (lists.get(17)).add(person); i feel give me null pointer exception? perhaps not. input/example code appreciated.
the constructor array list takes number determines initial capacity of list, not it's size.
thus when do:
list<object> list = new arraylist<object>(32); system.out.println(list.size()); // prints 0! instead, initialize list adding objects it:
// note passing 32 here optimization; tells list // plan add 32 elements can pre-allocate appropriate amount // of space. have done new arraylist<queue<passenger>>() list<queue<passenger>> queues = new arraylist<queue<passenger>>(32); (int = 0; < 32; ++i) { queues.add(new linkedlist<passenger>()); } // work queues.get(17).add(person);
Comments
Post a Comment