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 is the best option for general purpose use. If you need to fill large arrays though as of latest idk 1.8 u102, there is a faster way that leverages System.arraycopy. You can take a look at this alternate Arrays.fill implementation:
According to the JMH benchmarks you can get almost 2x performance boost for large arrays (1000 +)
In any case, these implementations should be used only where needed. JDKs Arrays.fill should be the preferred choice.