BAEL-5643 : Replace at Specific Index in Java ArrayList (#12539)

This commit is contained in:
ACHRAF TAITAI 2022-07-30 14:22:59 +02:00 committed by GitHub
parent ef758acef0
commit d0ba47e75d
1 changed files with 21 additions and 0 deletions

View File

@ -0,0 +1,21 @@
package com.baeldung.list.replace;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
class ReplaceUsingIndexInArrayListUnitTest {
private static final List<Integer> EXPECTED = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5));
@Test void givenArrayList_updateUsingSet() {
List<Integer> aList = new ArrayList<>(Arrays.asList(1, 2, 7, 4, 5));
aList.set(2, 3);
assertThat(aList).isEqualTo(EXPECTED);
}
}