I have a char []
, and I want to set the value of every index to the same char
value.
There is the obvious way to do it (iteration):
<
Arrays.fill(myArray, 'c');
Arrays.fill
Although it is quite possible that this is doing the loop in the background and is therefore not any more efficient than what you have (other than the lines of code savings). If you really care about efficiency, try the following in comparison to the above:
int size = 50;
char[] array = new char[size];
for (int i=0; i
Notice that the above doesn't call array.size() for each iteration.