我现在正在编写单元测试,我需要创建一个特定的字符串。
我现在定义了这样的东西:
private final String at = "@:";
private String error, effect, one, two, three, four;
在设置中(@Before):
error = RandomStringUtils.randomAlphabetic (3);
one = RandomStringUtils.randomAlphabetic (6);
two = RandomStringUtils.randomAlphabetic (8);
three = RandomStringUtils.randomAlphabetic (2);
four = RandomStringUtils.randomAlphabetic (6);
effect = (error + at + one + at + two + at + three + at + four);
字符串与加号的组合看起来非常丑陋和业余。是否有可能使用其他任何东西以某种方式更有效地做到这一点?例如模式?我不知道。感谢您的帮助:)
最佳答案
为简单起见,您还可以:
String.join(at, error,one, two, three, four);
关于java - 不使用 plus '+' 组合字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47030228/