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:
This worked out for me without using any external libraries in Java 8
String sampleText = "test" int n = 3; String output = String.join("", Collections.nCopies(n, sampleText)); System.out.println(output);
And the output is
testtesttest