A simple solution is to convert to a String, then use the .trim() method.