java detect new line in string

www.l‮‬autturi.com
java detect new line in string

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
Created Time:2017-09-22 23:16:31  Author:lautturi