Create a string with n characters

前端 未结 27 1184
猫巷女王i
猫巷女王i 2020-11-28 22:12

Is there a way in java to create a string with a specified number of a specified character? In my case, I would need to create a string with 10 spaces. My current code is:

27条回答
  •  猫巷女王i
    2020-11-28 22:47

    The for loop will be optimized by the compiler. In such cases like yours you don't need to care about optimization on your own. Trust the compiler.

    BTW, if there is a way to create a string with n space characters, than it's coded the same way like you just did.

提交回复
热议问题