Online Java Compiler By
JavaTpoint.com
import java.lang.reflect.Array; import java.math.BigDecimal; import java.math.BigInteger; import java.util.Arrays; public class ReflectArraynewInstanceExample2 { public static void main(String... args) { int lnth = 4; Object obj = Array.newInstance(BigDecimal.class, lnth); for (int i = 0; i < lnth; i++) { Array.set(obj, i, BigDecimal.valueOf(i)); } System.out.println(Arrays.toString((Object[]) obj)); } }
Output