added java implementation for remove_spaces