Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I print "\t" (as it looks) in Java?

Tags:

java

string

I want to print backslash t in Java. But whenever I try, it actualy takes it as \t operator. Double backslash didn't work. How can I do that.

like image 887
jessica Avatar asked Feb 12 '11 16:02

jessica


People also ask

Can we use \t in Java?

Java code for the escape sequence \t: // \t -> It gives a tab between two words.

How do you give a tab space in Java?

you can give tab space in java easily. "\t" is the space sequence in java programming.

How many spaces does \t do in Java?

Four spaces should be used as the unit of indentation. The exact construction of the indentation (spaces vs. tabs) is unspecified. Tabs must be set exactly every 8 spaces (not 4).


1 Answers

Escape the backslash by adding another, for example

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

If this doesn't work, there might be something else wrong in your code - please post it if this doesn't help you.

like image 153
Esko Avatar answered Nov 12 '22 13:11

Esko