Improved list Java code