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
************
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