// CSE 143, Winter 2010, Marty Stepp // This program uses the ArrayList class to create a list of integers. // It uses the Integer "wrapper class" to do this, because you can't create // an ArrayList. // This program also demonstrates a method that accepts a list as a parameter. import java.io.*; import java.util.*; public class ProcessFile2 { public static void main(String[] args) throws FileNotFoundException { // int[] numbers = new int[1000]; ArrayList numbers = new ArrayList(); Scanner input = new Scanner(new File("numbers.txt")); while (input.hasNextInt()) { int n = input.nextInt(); numbers.add(n); } System.out.println(numbers); filterEvens(numbers); System.out.println(numbers); } // Removes all elements with even values from the given list. public static void filterEvens(ArrayList list) { for (int i = 0; i < list.size(); i++) { int n = list.get(i); if (n % 2 == 0) { list.remove(i); i--; } } } }