How can I type "\ t" (what it looks like) in Java?

I want to print a backslash in Java. But whenever I try, it takes it as the \ t operator. Double backslash does not work. How can i do this.

+7
source share
8 answers

Remove the backslash by adding another, e.g.

System.out.println("This is a tab \t and this is not \\t"); 

If this does not work, maybe something else is wrong in your code - write if this does not help you.

+15
source

You need to escape "\" with another "\"

 System.out.println("\\t"); 
+8
source

Double backslash works.

 public static void main(final String[] args) { System.out.println("\\t"); } 

will output \ t

+3
source
 public static void main(String[] args) { System.out.println("\"\t\""); } 
+1
source
 System.out.println("\"\\t\""); 

if you need even double quotes :)

+1
source

To add a tab to java, this process will be the same as c and java

In C: -
printf("This will display the tab example \t After tab");

In Java: -
System.out.println("This will display the tab example \t After tab");

The same will be for a new line
System.out.println("This will display the New Line example \n Next Line");

0
source
 System.out.println("\" + "t"); 

this wille print: \t easy!

0
source
 System.out.println("\\"+"\\t"); 

Shows: \t

0
source

All Articles