Skip to content

Merge an List of Object and an Object to a new array in Java [closed]

I have List<BigInteger> sample1 = Lists.newArrayList(BIGINTEGER1, BIGINTEGER2,BIGINTEGER3);

I have to create new List sample2 with one more value BIGINTEGER4 along with sample1 list:

How can I do that?


You can create a new ArrayList, and pass the other list in the constructor – the contents from the other list will then be passed/copied into the new:

List<BigInteger> sample2 = new ArrayList<>(sample1);