Basically, given int, I need to generate a String with the same length containing only the specified character. A related question is here , but it relates to C #, and it matters what's in the line.
This question , and my answer to this is why I ask about it. I'm not sure the best way to do this is in terms of performance.
Example
Method Signature:
String getPattern(int length, char character);
Using:
//returns "zzzzzz" getPattern(6, 'z');
What i tried
String getPattern(int length, char character) { String result = ""; for (int i = 0; i < length; i++) { result += character; } return result; }
Is this the best I can do in terms of performance?
source share