SimpleArrayListExample

SimpleArrayListExample - printArrayList(list private void...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
/* * SimpleArrayListExample.java * --------------------------- * This program shows an example of using an ArrayList. */ import acm.program.*; import java.util.*; public class SimpleArrayListExample extends ConsoleProgram { public void run() { setFont("Courier New-24-Bold"); ArrayList<Integer> list = new ArrayList<Integer>(); readList(list); printArrayList(list); readList(list);
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: printArrayList(list); } private void readList(ArrayList<Integer> list) { while (true) { Integer item = readInt("? "); if (item == 0) break; list.add(item); } } private void printArrayList(ArrayList list) { println("List contains " + list.size() + " elements"); for(int i = 0; i < list.size(); i++) { println(list.get(i)); } } }...
View Full Document

This note was uploaded on 02/18/2010 for the course CS 106A taught by Professor Sahami,m during the Fall '08 term at Stanford.

Ask a homework question - tutors are online