What is the easiest way to generate a String of n repeated characters?

后端 未结 8 1745
时光说笑
时光说笑 2020-12-15 16:25

Given a character c and a number n, how can I create a String that consists of n repetitions of c? Doing it manually is too cumbersome:

StringBuilder sb = ne         


        
8条回答
  •  醉酒成梦
    2020-12-15 16:52

    Google Guava Time!

    Strings.repeat("a", 3)
    

    http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/base/Strings.html

提交回复
热议问题