Skip to content
Advertisement

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?

Advertisement

Answer

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);
sample2.add(BIGINTEGER4);
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement