determine whether there is a new line in java string
/** * @author lautturi.com * Java example:check whether there is a new line in the java string */ public class Lautturi { public static void main(String[] args) { String str = "A string \r\n with a new Line inside"; String newline = System.getProperty("line.separator"); boolean hasNewline = str.contains(newline); if (hasNewline) { System.out.println("has new line"); } } }
output:
has new line break