function to check new line in java code example
Example 1: java detect new line in string
String word = "A string \n with a new Line inside"
String newline = System.getProperty("line.separator");
boolean hasNewline = word.contains(newline);
if(hasNewLine){
System.out.println("Enter has been pressed");
}
Example 2: java new line
String line1 = "Humpty Dumpty sat on a wall.";
String line2 = "Humpty Dumpty had a great fall.";
String rhyme = line1 + "\n" + line2;