IntList - package lab10; p public class IntList { p /** * A...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: package lab10; p public class IntList { p /** * A growable collection of ints. */ /** * The list of integers. It may contain more elements than are actually * filled. */ protected int list; /** * The actual number of elements in list that contain a value. */ protected int size; /** * Create a new, empty list of integers. We create spots for 10 numbers, * and we'll grow the array if these all fill up. */ public IntList() { list = new int[10]; size = 0; } /** * Get the number of items in the list. * @return Number of items in list. */ public int size() { return size; } /** * Get the item at position i * * @param i * Index of item to retrieve. * * @return * Item at position i * * @throws ArrayIndexOutOfBoundsException * If position invalid. */ public int get(int i) { if (i >= size) { throw new ArrayIndexOutOfBoundsException(); } return list[i]; } /** * Add an int to the end of the list. The list is grown automatically if * its current capacity has been reached....
View Full Document

This note was uploaded on 09/20/2011 for the course COM SCI 227 taught by Professor Staff during the Spring '11 term at Iowa State.

Page1 / 3

IntList - package lab10; p public class IntList { p /** * A...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online