Methods of ArrayList
Application:
import java.util.ArrayList; public class Application { public static void main(String[] args) { ArrayList<Integer> someInts = new ArrayList<Integer>(); int[] nums = {5, 7, 2, 15}; for (int i = 0; i < nums.length; i++) { someInts.add(nums[i]); } someInts.set(3, 100); // Display the sum int sum = 0; for (int i = 0; i < someInts.size(); i++) { sum += someInts.get(i); } System.out.println("sum is " + sum); } }
|