Java examples for java.lang:String Contain
Tells whether or not the given string contains or not new line characters (both line feed as carriage return).
//package com.java2s; import java.util.regex.Pattern; public class Main { public static void main(String[] argv) { String string = "java2s.com"; System.out.println(containsNewLineChars(string)); }/*from w ww . ja va2s .co m*/ /** * Tells whether or not the given {@code string} contains or not new line characters (both line feed as carriage return). * * @param string the string that will be tested * @return {@code true} if the string contains at least one new line character, {@code false} otherwise. */ public static boolean containsNewLineChars(String string) { return Pattern.compile("\\r?\\n").matcher(string).find(); } }