Go #4: Refactor logic out of main function
Java: Use TreeSet for sorted collections

Importantly, these collections also do not need to store duplicates.
Java #3: Do not use polymorphism in factors()

There is no need to initialize factors as a List and then downcast it as
an ArrayList later on. The collection can be an ArrayList all along.

This was probably useful at some point during the initial implementation
(before anything was committed) but was no longer needed after some
refactoring. Leaving this approach in was just an oversight.