ray ray - 1 year ago 257
Java Question

Declare Initial Value of BigDecimal Array in Java

I want to declare a

with initial value
like this:

BigDecimal[] val = {0,0,0};

but it's not working. Please help me to know how to declare
with initial value.

Answer Source

I would use Arrays.fill() as that will would for any number of zeros (or any other BigDecimal value you like) This works because BigDecimal is immutable, don't do this for mutable values ;)

BigDecimal[] val = new BigDecimal[N];
Arrays.fill(val, BigDecimal.ZERO);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download