Code cleanup :
- Removed "final" for static and private methods;
- for (int i = 0; i < ar.length; i++) replaced with "for each" where possible
- removed unnecessary type/class castings;
- a.toArray(new T[0]) replaced with a.toArray(new T[a.size()]);