Win a copy of Head First Android this week in the Android forum!

Mark Lund

Greenhorn
+ Follow
since Jun 15, 2006
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mark Lund

Not bad I guess for an 'old' Cobol programmer. I only posted a few times but eagerly read the forums here for info. I send a big thanks to Kathy and Bert for their great book. Next stop - SCBCD.
14 years ago
I also have never been able to retrieve the extra test exam. Have registered, tried to reregister which fails, requested password numerous times which never arrives. I've given up. Hope next B&K book will be with a 'reliable' publisher.

Mark
Thanks guys. You've been very helpful! Mark
This seems pretty basic but can't figure out why the enums appear to be unsorted in the second TreeSet. Am studying SCJP and don't feel real strong here so please give me some pointers. I can't override compareTo or equals and hashCode for that matter. This is not from any book. Mark

import java.util.*;

class TestCollect{

enum Children{
Michelle,
Lisa,
Sarina,
Brenda;
}

public static void main(String [] argv){
Set <String> set= new TreeSet<String>();
set.add(Children.Michelle.toString());
set.add(Children.Lisa.toString());
set.add(Children.Sarina.toString());
set.add(Children.Brenda.toString());
for (String i:set)
System.out.println(""+i);

Set <Children> set2= new TreeSet<Children>();
set2.add(Children.Michelle);
set2.add(Children.Lisa);
set2.add(Children.Sarina);
set2.add(Children.Brenda);
for (Children i:set2)
System.out.println(i.name());
}
}