Collections handling classes could be improved, in different ways:
- More functional oriented methods: it allow developers to produce more compact and expressive code. Also that code is more easy to be parallelized.
filter(list, predicate or lambda) is better than foreach item in list if lambda(item) filtered_list.add(item)
- Add more convenience methods: default parameters, simpler signature, etc.
method(param) is better than method(param, null, null, -1, null)
- Add more semantic methods: the aim is to produce self-expressive code.
if exists(list, item) ... is better than if count(list, item) > 0 ...
- Reduce side effects: it's always more convenient to create new data structures with the result of some computations instead of modifying the original one
filtered_list = filter(list) is better than filter(list) // list is modified at this point
- Use proper abstractions: always use the more generic abstraction available. The use of too specific classes leads to less-reutilizable method
filter(abstract_list) is better than filter(specific_list)
- Rely on standard implementation: Java Collections Framework implements a lot of algorithms and data manipulation routines.
- Use third party well known libraries if you need inspiration. Use those algorithm implementations instead yours if they have better BigO performance