如何在java中插入多个选项卡字符串?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18021435/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 21:51:01  来源:igfitidea点击:

How to insert multiple tabs string in java?

javastring

提问by user2646617

How to insert multiple tabs string in java?

如何在java中插入多个选项卡字符串?

ex : getName() + '\t' + '\t' +getLastName()" Doesn't work. Please Help!!

例如:getName() + '\t' + '\t' +getLastName()" 不起作用。请帮助!!

采纳答案by Marko Topolnik

Your example should work; however there's no reason to append each tab character individually. This works, too:

你的例子应该有效;但是没有理由单独附加每个制表符。这也有效:

getName() + "\t\t" + getLastName();

The errors you are getting are not related to the tab characters.

您得到的错误与制表符无关。

回答by bean

Your syntax is screwy. Try this.

你的语法很糟糕。尝试这个。

 String whatever0 = "firstname"+"\t"+"\t"+"lastname";
 String whatever1 = "firstname"+"\t"+"\t"+"\t"+"lastname";
 System.out.println(whatever0);
 System.out.println(whatever1);

You'll see that they give different results.

你会看到它们给出不同的结果。