If I have a rarely used collection in some class which may be instantiated many times, I may sometimes resort to the following \"idiom\" in order to save unnecessary object crea
emptyList() doesn't allocate an object each time.
I would create less of the object which contains the List so you can create the list every time.
What you can do is
private List list = Collections.emptyList(); private List listForWrite() { return list.isEmpty() ? list = new ArrayList() : list; } void add(Object object) { listForWrite().add(object); } // avoid creating an Iterator every time. for (int i = 0, size = list.size(); i < size; i++) { ; }