Hello all. I am still stuck on this Comparator class I have built with comparing Strings. there are no syntax errors, but it does not run. Can someone tell me what is wrong with this?
public class VehicleColorComparator
implements Comparator<Vehicle>, java.io.Serializable
// uses the inherited compare method for the colors
public int compare (Vehicle o1, Vehicle o2)
String Color1 = o1.color;
String Color2 = o2.color;
if(Color1.compareTo(Color2) > 0)
String has a built in compareTo, so your compare method could just be
Define "does not run". Do you get exceptions? Does it sort when you try to use the comparator, for example sort using Collections.sort?
but it does not run
Sorry for the confusion. I was trying to use the compareTo method the strings already have, but the homework I was using was giving me fits. I think I got it, so I will solve this thread and post back if I have a problem in a few hours.
Thanks all and sorry for the confusion once again.