如何在Java中使用这个C#语法示例?

huangapple go评论100阅读模式
英文:

How use this c sharp syntax example in java?

问题

如何在Java字符串中插入(a)和(b)?

String a = "David";
String b = "Mike";
System.out.println("这是 {0} 和 {1} 的测试", a, b);
英文:

How insert (a) and (b) in string line in java?

string a = "David";
string b= "Mike";
Console.WriteLine("This is test for {0} and {1}",a,b);

答案1

得分: 1

你正在寻找名为 "String Interpolation" 的东西。
自从 Java 5 开始,你可以使用以下方法:

String s = String.format("这是 %s 和 %s 的测试", a, b);
英文:

You are looking for something called "String Interpolation".
Since Java 5 you can use this:

String s = String.format("This is test for %s and %s", a, b);

huangapple
  • 本文由 发表于 2020年8月3日 03:27:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/63220205.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定