Simple way to repeat a string

后端 未结 30 3042
清酒与你
清酒与你 2020-11-21 06:55

I\'m looking for a simple commons method or operator that allows me to repeat some string n times. I know I could write this using a for loop, but I wish to avoid f

30条回答
  •  情书的邮戳
    2020-11-21 07:11

    Commons Lang StringUtils.repeat()

    Usage:

    String str = "abc";
    String repeated = StringUtils.repeat(str, 3);
    
    repeated.equals("abcabcabc");
    

提交回复
热议问题