How to remove newlines from beginning and end of a string?
String.replaceAll("[\n\r]", "");
Use String.trim()
method to get rid of whitespaces (spaces, new lines etc.) from the beginning and end of the string.
String trimmedString = myString.trim();