Simple way to repeat a string

后端 未结 30 3137
清酒与你
清酒与你 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条回答
  •  猫巷女王i
    2020-11-21 07:02

    I created a recursive method that do the same thing you want.. feel free to use this...

    public String repeat(String str, int count) {
        return count > 0 ?  repeat(str, count -1) + str: "";
    }
    

    i have the same answer on Can I multiply strings in java to repeat sequences?

提交回复
热议问题