Util: various improvements to toXArray functions

* use Iterator contract instead of getRest()
* use System.arraycopy where possible
* nullsafe
* whitespace fixes (untabify, trailing spaces)

Closes #232.