Remove element from array

This example will use apache commons ArrayUtils.removeElement to show how to remove an element from an array. Specifically, the utility class will remove the first occurrence it finds and then shift the elements to the left.

Apache Commons

@Test
public void remove_element_from_array_apache_commons () {

    String[] daysOfWeek = {"Sunday", "Monday", "Tuesday", "Wednesday",
            "Thursday", "Friday", "Saturday"};

    String[] favoriteDaysOfTheWeek = ArrayUtils.removeElement(daysOfWeek, "Monday");

    logger.info(Arrays.toString(daysOfWeek));

    assertTrue(favoriteDaysOfTheWeek.length == 6);
    assertThat(favoriteDaysOfTheWeek, arrayContaining(
            "Sunday", "Tuesday", "Wednesday",
            "Thursday", "Friday", "Saturday"));

}