Hi again,
I looked over the discussion board. I do not see anyone setting the initial
capacity.
I am unable to understand what set is being implemented?
//Create HashSet with initial capacity of 5.
Set set = new HashSet(5);
//Create new treeSet object.
set = new TreeSet(new MyComparator());
//add elements
set.add("String one");
set.add("String two");
Alex
--- On Wed, 11/4/09, * ^ * <[email protected]> wrote:
From: * ^ * <[email protected]>
Subject: [java programming] Re: Lab1008_2.4
To: "Java Programming Online Training Course By Sang Shin"
<[email protected]>
Date: Wednesday, November 4, 2009, 5:04 AM
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
-~----------~----~----~----~------~----~------~--~---