In Python, there is a *
operator for strings, I'm not sure what it's called but it does this:
>>> "h" * 9
"hhhhhhhhh"
Is there an operator in Java like Python's *
?
Many libraries have such utility methods.
E.g. Guava:
String s = Strings.repeat("*",9);
or Apache Commons / Lang:
String s = StringUtils.repeat("*", 9);
Both of these classes also have methods to pad a String's beginning or end to a certain length with a specified character.
I think the easiest way to do this in java is with a loop:
String string = "";
for(int i=0; i<9; i++)
{
string+="h";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With