I stuck a little. I have a method, which should return a new String contains X times repeated character "y". X and Y are arguments of method. So, simple solution wiil be like this:
public String someMethod(int x,char y){
String result="";
for (int i=0;i<x;i++) result+=y;
return result;
}
And I've tried to figure out, is there any way to do the same just in one line, without looping. For example:
public String someMethod(int x,char y){
return new StringBuilder().append('y', x);
}
But there isn't such method for StringBuilder or StringBuffer or etc. Can you give me any suggestions? Thanks in advance.
Updated: So, the solution will be:
public String someMethod(int x,char y){
return new String(new char[x]).replace("\0", String.valueOf(y))
}
Thanks for help!