Skip to content

Commit

Permalink
New line in Java for HTML and Changing HTML file
Browse files Browse the repository at this point in the history
  • Loading branch information
rahusriv committed Nov 8, 2018
1 parent b9b4cec commit 6dd09ae
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,63 @@ public static void main(String[] args) {
String line2 = "Humpty Dumpty had a great fall.";
String para = "";

System.out.println("***New Line in a String in Java***");
//1. Using "\n"
System.out.println("1. Using \\n");
para = line1+"\n"+line2;
para = line1 + "\n" + line2;
System.out.println(para);

//2. Using "\r\n"
System.out.println("2. Using \\r\\n");
para = line1+"\r\n"+line2;
para = line1 + "\r\n" + line2;
System.out.println(para);

//3. Using "\r"
System.out.println("3. Using \\r");
para = line1+"\r"+line2;
para = line1 + "\r" + line2;
System.out.println(para);

//4. Using "\n\r" Note that this is not same as "\r\n"
// Using "\n\r" is equivalent to adding two lines
System.out.println("4. Using \\n\\r");
para = line1+"\n\r"+line2;
para = line1 + "\n\r" + line2;
System.out.println(para);

//5. Using System.lineSeparator()
System.out.println("5. Using System.lineSeparator()");
para = line1+System.lineSeparator()+line2;
para = line1 + System.lineSeparator() + line2;
System.out.println(para);

//6. Using System.getProperty("line.separator")
System.out.println("6. Using System.getProperty(\"line.separator\")");
para = line1+System.getProperty("line.separator")+line2;
para = line1 + System.getProperty("line.separator") + line2;
System.out.println(para);

//Line break for HTML using <br>
System.out.println("Line break for HTML using <br>");
para = line1+"<br>"+line2;
System.out.println("***HTML to rendered in a browser***");
//1. Line break for HTML using <br>
System.out.println("1. Line break for HTML using <br>");
para = line1 + "<br>" + line2;
System.out.println(para);

//2. Line break for HTML using “&#10;”
System.out.println("2. Line break for HTML using &#10;");
para = line1 + "&#10;" + line2;
System.out.println(para);

//Line break for HTML when string is in <textarea> tag
para = line1+"&#10;"+line2;
para = line1+"&#13;"+line2;
//3. Line break for HTML using “&#13;”
System.out.println("3. Line break for HTML using &#13;");
para = line1 + "&#13;" + line2;
System.out.println(para);

//Line break for HTML when string is in <pre> tag
para = line1+"&#10;"+line2;
para = line1+"&#10;&#13;"+line2;
para = line1+"<br>"+line2;
//4. Line break for HTML using “&#10&#13;;”
System.out.println("4. Line break for HTML using &#10;&#13;");
para = line1 + "&#10;&#13;" + line2;
System.out.println(para);

//5. Line break for HTML using \n”
System.out.println("5. Line break for HTML using \\n");
para = line1 + "\n" + line2;
System.out.println(para);
}

}
}
29 changes: 24 additions & 5 deletions core-java/src/main/java/com/baeldung/string/page.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
<html>
<body>
Humpty Dumpty sat on a wall.<br>Humpty Dumpty had a great fall.
Humpty Dumpty sat on a wall.<br>Humpty Dumpty had a great fall.<br>
Humpty Dumpty sat on a wall.&#10;Humpty Dumpty had a great fall.<br>
Humpty Dumpty sat on a wall.&#13;Humpty Dumpty had a great fall.<br>
Humpty Dumpty sat on a wall.&#10;&#13;Humpty Dumpty had a great fall.<br>
Humpty Dumpty sat on a wall.
Humpty Dumpty had a great fall.
<br>
<textarea>Hello<br>Baeldung</textarea>
<textarea>Hello&#10;Baeldung</textarea>
<textarea>Hello&#13;Baeldung</textarea>
<pre>Humpty Dumpty sat on a wall.&#10;&#13;Humpty Dumpty had a great fall</pre>
<pre>Humpty Dumpty sat on a wall.&#13;Humpty Dumpty had a great fall</pre>
<pre>Humpty Dumpty sat on a wall.&#10;Humpty Dumpty had a great fall</pre>
<textarea>Hello&#10;&#13;Baeldung</textarea>
<textarea>Hello.
Baeldung</textarea>
<br>
<pre>Humpty Dumpty sat on a wall.<br>Humpty Dumpty had a great fall.</pre>
<pre>Humpty Dumpty sat on a wall.&#10;Humpty Dumpty had a great fall.</pre>
<pre>Humpty Dumpty sat on a wall.&#13;Humpty Dumpty had a great fall.</pre>
<pre>Humpty Dumpty sat on a wall.&#10;&#13;Humpty Dumpty had a great fall.</pre>
<pre>Humpty Dumpty sat on a wall.
Humpty Dumpty had a great fall</pre>
<br>
<p>Humpty Dumpty sat on a wall.<br>Humpty Dumpty had a great fall</p>
<p>Humpty Dumpty sat on a wall.&#10;Humpty Dumpty had a great fall</p>
<p>Humpty Dumpty sat on a wall.&#13;Humpty Dumpty had a great fall</p>
<p>Humpty Dumpty sat on a wall.&#10;&#13;Humpty Dumpty had a great fall</p>
<p>Humpty Dumpty sat on a wall.
Humpty Dumpty had a great fall</p>
</body>
</html>
</html>

0 comments on commit 6dd09ae

Please sign in to comment.