Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem in user define Comparator

Status
Not open for further replies.

ketandba

Programmer
Nov 15, 2004
38
US
i have problem in my user define comparator.
************
public interface MyComparator {

public int compare(Object obj1, Object obj2);
}

************

public class CreateTreeMap implements MyComparator{

public CreateTreeMap (){

String name1 ;
String name2;

String clientNameArray [] = {"X","i","b","A","C","y"};
String valueArray [] = {"one","two","three","four","five","six"};

TreeMap map_tree = new TreeMap();

for (int i=0; i<6; i++){
name1 = clientNameArray;
map_tree.put(name1, valueArray);
}

}


public int compare(Object obj1, Object obj2 ){
String name1 = (String)obj1;
String name2 = (String)obj2;
name1 = name1.toLowerCase();
name2 = name2.toLowerCase();
return name1.compareToIgnoreCase (name2) ;

}// end compare


}// end treeMap class

**********testCreatTreeMap*********
public class TestCreateTreeMap {
public static void main(String [] args) {

TestCreateTreeMap testCreateTreeMap = new TestCreateTreeMap();
testCreateTreeMap.makeClientTreeMap();
}
public void makeClientTreeMap(){
// here i get the error ----- The constructor TrrMap(CreateTreeMap) is undefined...(below line)
SortedMap smp = new TreeMap(new CreateTreeMap()); // at this line (E R R O R --- The constructor TrrMap(CreateTreeMap) is undefined
// -----above --- line
smp.put("X", "one");
smp.put("a", "two");
smp.put("y", "three");
smp.put("b", "four");

System.out.println("Sorted TreeMap on key");
Iterator iter1 =
smp.keySet().iterator();
while (iter1.hasNext()) {
System.out.println(iter1.next());
}

}
}

********end ******


i am very fresh in java... pl. guide me...

Your help is appriciated...

ketan
 
One Constructor expects a Comparator as Argument.
Your Class implements MyComparator, which isn't Comparator (or derived from it).

Try
Code:
public class CreateTreeMap implements Comparator
and remove your MyComparator.

And it's a JDK-question, better suited in

Home > Forums > Programmers > Languages > Java (Sun) Forum

seeking a job as java-programmer in Berlin:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top