How To Make a Line Break/New Line in Java

How To Make a Line Break/New Line in Java
Line Break or New Line : I hope you understand what it is, in HTML you use <br> tag to make a new line so in Java if you want to make a new line it's not that hard but it has several methods depends on the platform.

Coming to the point, most of the java beginners think this is the one and only way to make a new line : System.out.println("\n"); but It's not true.. let me tell you something you might think that whatever you program using java will work on other java supported platforms, YES! they will work on other platforms but there are few things that has to be changed in order to get the functions work.. for example this tutorial; this line of code : System.out.println("\n"); would make a new line only on Windows. As I said before there are few things that are different from platform to platforms.

If you want to make a new line on Mac you must use this : System.out.println("\r"); and for Linux you have to use this : System.out.println("\r\n");. So I came up with something that works on all the platforms, It's pretty simple and works perfectly.

First you need to make a public string and set the value to make a new line(You can also just make normal string and set the value)
Add this line of code before your main event
public static String breakline = System.getProperty("line.separator");

Whenever you need to make a new line just use this line of code 
You can add this wherever you want to
System.out.println(breakline);

Please comment if you have any doubts..!

19 comments

Excellent post!!! Java is most popular and efficient programming language available in the market today. It helps developers to create stunning desktop/web applications loaded with stunning functionalities. Best JAVA Training in Chennai

Reply

what is the command using php and dotnet newline and break line command. becz i have dnt know programming language, selenium Training in Bangalore | Oracle Training in Bangalore

Reply


Looking for a career in technology industry? Wonder what are the languages that will give just the right start to your career?
Over to the hottest programming languages you can learn in 2015.

Corporate Training

Reply

I agree with your thoughts!!! As the demand of java programming application keeps on increasing, there is massive demand for java professionals in software development industries. Thus, taking training will assist students to be skilled java developers in leading MNCs. JAVA J2EE Training in Chennai | JAVA J2EE Training Institutes in Chennai

Reply

The information you have deliver here is really useful to make my knowledge good. Thanks for your heavenly post. It is truly supportive for us and I have accumulated some essential data from this blog.
Regards,
sas training in Chennai|sas course in Chennai|sas training institute in Chennai

Reply

Hi, This is really nice blog. You have done really great job. Keep posting. I did Java Training in Chennai at TIS academy. Its really useful for me to make a bright future in IT industry.

Reply

Thanks for sharing this niche useful informative post to our knowledge, Actually SAP is ERP software that can be used in many companies for their day to day business activities it has great scope in future.
Regards,
SAP training in chennai|SAP course in chennai|SAP Training in Chennai|sap training in Chennai

Reply

Awesome Post! I like writing style, how you describing the topics throughout the post. I hope many web reader will keep reading your post at the end, Thanks for sharing your view.
Regards,
Angularjs training in chennai|Angularjs training chennai|Angularjs course in chennai|Angularjs training center in Chennai

Reply

most useful information article,
great posting it author,
learn seo and complete digital marketing course with our best seo experts
seo training in bangalore

Reply

Dear admin, The way you have explained the concept is mezmerizing. Thank you so much for sharing tis worth able content with us. The concept taken here will be useful for my future programs and i will surely implement them in my study. Keep blogging article like this.


JAVA Training in Chennai | Best JAVA Training in Chennai | Android training in chennai

Reply

Hello,

The great article on Java to Make a Line Break/New Line

Java Online Course | Java Training in Chennai | J2EE Training in Chennai

Reply

Really awesome blog. Your blog is really useful for me.
Thanks for sharing this informative blog. Keep update your blog.
Oracle Training In Chennai

Reply

I am reading ur post from the beginning, it was so interesting to read & i feel thanks to you for posting such a good blog, keep updates regularly.Best Hadoop Training Institute In Chennai

Reply

Great article.I learned some new concept. Thanks for sharing.
Web designing training in chennai

Reply

Thanks for sharing this informative post to our vision..
QTP Training in Chennai

Reply

Excellent post!!! Java is most popular and efficient programming language available in the market today. It helps developers to create stunning desktop/web applications loaded with stunning functionalities. Java Course in Chennai | Best JAVA Training in Chennai

Reply

Really great post thanks for fabulous sharing and also informative IOS Design And Development

Reply

You have done really great job. Keep update your blog. Thanks..Software Testing Training in Chennai

Reply

Post a Comment