Menu
  • HOME
  • TAGS

ArrayList vs HashMap - Lots of Iterating and Object Manipulation

java,multithreading,arraylist,hashmap,copyonwritearraylist

This answer addresses your concurrency concerns: A lot of iteration and object manipulation will need to be performed constantly (each main loop iteration can result in every single object in the data structure being modified in worst case, nothing modified in best/normal case). Will the collection be modified? If not...

How to sort CopyOnWriteArrayList

java,core,copyonwritearraylist

Collections.sort uses ListIterator.set ... for (int j=0; j<a.length; j++) { i.next(); i.set((T)a[j]); } but CopyOnWriteArrayList's ListIterator does not support the remove, set or add methods. Workaround: Object[] a = list.toArray(); Arrays.sort(a); for (int i = 0; i < a.length; i++) { list.set(i, (String) a[i]); } ...

Should Iterator or Iterable be used when exposing internal collection items?

java,arraylist,iterator,iterable,copyonwritearraylist

The "best" solution actually depends on the intended application patterns (and not so much on "opinions", as suggested by a close-voter). Each possible solution has pros and cons that can be judged objectively (and have to be judged by the developer). Edit: There already was a question "Should I return...