It is suddenly necessary to repeat a string n times instead of a loop method, and the result is not.
Csdn was found, and people said no. There are many ways to find the most efficient. Post it and give it to everyone as the highest efficiency
Public
Static
StringRepeatstring (StringSTR,IntN)
{
Char[] Arr = Str. tochararray ();
Char[] Arrdest =New
Char[Arr. length * n];
For(IntI = 0; I <n; I ++)
{
Buffer. Blockcopy (ARR, 0, arrdest, I * arr. length * 2, arr. length * 2 );
}
Return
New
String(Arrdest );
}
It seems that memory allocation is highly efficient, maybe ~~ :)
Will it be inefficient to change this method to a generic one?
Public
Static
StringRepeatstring <t> (t str,IntN)
{
StringS = Str. tostring ();
Char[] Arr = S. tochararray ();
Char[] Arrdest =New
Char[Arr. length * n];
For(IntI = 0; I <n; I ++)
{
Buffer. Blockcopy (ARR, 0, arrdest, I * arr. length * 2, arr. length * 2 );
}
Return
New
String(Arrdest );
}
}