A couple of useful Algorithms in Java