The pseudo-code author refers to a recursive definition of a list: a list is an element and a list (rest). There's nothing quite like that in Java at all.
I think your professor intends for you to write a recursive linked list. It's not as hard as writing a list-of-nodes - you'd use lists-of-nodes for performance reasons, recursive lists for academic reasons!
I just typed up a recursive list out of interest, but posting it here would certainly be spoonfeeding! Here's my main method:
public static void main(String[] args)
{
CrazinsList<Character> listJPF = new CrazinsList<Character>();
for (char c : "JavaProgrammingForums.Com".toCharArray())
listJPF.add(c);
System.out.println(listJPF + " is " + listJPF.size() + " long");
System.out.println(listJPF.get(0).toString() + listJPF.get(4).toString() + listJPF.get(15).toString());
System.out.println("Removed: " + listJPF.remove(20));
System.out.println(listJPF);
for (CrazinsList tmp = listJPF; tmp != null; tmp = tmp.rest)
System.out.println(tmp + " is " + tmp.size() + " long");
}
- you can see your 2-line 'for' statement at the bottom. And here's the output:
JavaProgrammingForums.Com is 25 long
JPF
Removed: s
JavaProgrammingForum.Com
JavaProgrammingForum.Com is 24 long
avaProgrammingForum.Com is 23 long
vaProgrammingForum.Com is 22 long
aProgrammingForum.Com is 21 long
ProgrammingForum.Com is 20 long
rogrammingForum.Com is 19 long
ogrammingForum.Com is 18 long
grammingForum.Com is 17 long
rammingForum.Com is 16 long
ammingForum.Com is 15 long
mmingForum.Com is 14 long
mingForum.Com is 13 long
ingForum.Com is 12 long
ngForum.Com is 11 long
gForum.Com is 10 long
Forum.Com is 9 long
orum.Com is 8 long
rum.Com is 7 long
um.Com is 6 long
m.Com is 5 long
.Com is 4 long
Com is 3 long
om is 2 long
m is 1 long
Done
Every method inside the CrazinsList class is implemented with recursion - no loops anywhere.