RU beehive logo ITEC dept promo banner
ITEC 120
2008fall
aaray,
ejderrick,
ibarland,
jmdymacek

homeinfolabshwsexams
textbookjava.lang docsjava.util docsarchive

lect10b
lists

A way of keeping track of a whole bunch of Strings

java.util.LinkedList<String> names = new java.util.LinkedList<String>();

names.add(0,"fred")
names.add(1,"jill")
names.add(2,"amy")
Let's go back and remember the 1000 numbers we read in above:

Name of the class is long and awkward: java.util.LinkedList<String> (or java.util.LinkedList<Double> or java.util.LinkedList<java.awt.Rectangle> or …) Sure, you can use “import” to get on a first name basis with LinkedList<String>, but you do need to include the “<String>”.

A method to add things (to the end) of a LinkedList<Type>:

   void add(Type val)

Okay, I lied; the signature is actually: boolean add(Type val); for lists this always returns true.

The complementary method, to retrieve things which were previously put into the list:

   void get(int i)

At Codepad, we'll declare and init a list of Double, ithen we'll add and retrieve several items.

homeinfolabshwsexams
textbookjava.lang docsjava.util docsarchive


©2008, Ian Barland, Radford University
Last modified 2008.Nov.10 (Mon)
Please mail any suggestions
(incl. typos, broken links)
to iba�rlandrad�ford.edu
Powered by PLT Scheme