Filtering an Array

From Progzoo
Jump to navigation Jump to search

A filter applies a test to each element - it removes any element that fails the test.

Use another array to filter

You can build up the return list in another array. Because we may not know the size of the resulting array, we use an ArrayList, which can grow in size as needed, to accumulate the results; and then we copy them back into an array.

Return only the even numbers in the input list.

[Font] [Default] [Show] [Resize] [History] [Profile]