Updating Encode.java answer to use Collectors (as outlined in review
comments)