Questions tagged «stringbuffer»


27
创建一个包含n个字符的字符串
java中有没有一种方法可以用指定数量的指定字符创建字符串?就我而言,我需要创建一个包含10个空格的字符串。我当前的代码是: StringBuffer outputBuffer = new StringBuffer(length); for (int i = 0; i < length; i++){ outputBuffer.append(" "); } return outputBuffer.toString(); 有没有更好的方法来完成同一件事。特别是我想快速(在执行方面)。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.