On Nov 4, 1:22 pm, happy27182 <[email protected]> wrote:
> Re:  Java Collections Frameworks 2.4hw
>  
> Hi:
>  
> I am going back over the course outline.  There seems to have been a change.  
> The exercises which were suggested to be done by oneself seemed to have been 
> changed to homework assignments.
>  
> I did most of them.  I am now working on the TreeSet one.  I received a class 
> cast exception for MyClassObj.  I want to do the following to correct this.
>  
> 1) Do I implement the Comparator interface in the MyClassObj Class file or in 
> it's own file?
The latter seems more feasible. For example:
class OrderbyStringComparator implements Comparator{
 int compare(Object $this, Object that){
  return String.valueOf($this).compareTo(String.valueOf(that));
 }
}

Thereafter, supply this comparator when creating the treeset:
TreeSet ts=new TreeSet(new OrderbyStringComparator);

Besides, there was a recent discussion about this, in which uses
anonymous class.
>  
> 2)  I am unsure how to call it.  Do I have to use the following constructor 
> to make my tree set object.
> TreeSet(Comparator<? super E> comparator)
> What do I fill in for the parameters if MyClassObj implements comparator?
>  
> I appreciate your help on this last one.  Thanks.
> Alex
>
>  
>  
>  
>  
>  

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to