What is the backslash character (\\)?

Y.E.P picture Y.E.P · Aug 23, 2012 · Viewed 116k times · Source

What is the string literal \\ backslash? What does it do? I have thought about it but I do not understand it. I also read it on wikipedia. When I try to print the following:

System.out.println("Mango \\ Nightangle");

the output is: Mango \ Nightangle

What is the significance of this string literal?

Answer

Chandra Sekhar picture Chandra Sekhar · Aug 23, 2012

\ is used as for escape sequence in many programming languages, including Java.

If you want to

  • go to next line then use \n or \r,
  • for tab use \t
  • likewise to print a \ or " which are special in string literal you have to escape it with another \ which gives us \\ and \"