Declare the initial value of BigDecimal array in Java

I want to declare a BigDecimal array with an initial value of 0, as follows:

BigDecimal[] val = {0,0};

But it doesn't work Please help me know how to declare BigDecimal array with initial value

Solution

I will use arrays Fill (), because it will apply to any number of zeros (or any other BigDecimal value you like). This is valid because BigDecimal is immutable. Do not do this for variable values;)

BigDecimal[] val = new BigDecimal[N];
Arrays.fill(val,BigDecimal.ZERO);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>