View Single Post
Old Nov 27th, 2005, 3:01 PM   #7
säkki
Newbie
 
Join Date: Feb 2005
Posts: 9
Rep Power: 0 säkki is on a distinguished road
OK thank you guys, finally got it working. Had some problems with the whole idea (what to do in which class etc). Post my solution here if it may help someone else.

In class Person:
//implements Comparable
-----------------------------
public int compareTo(Object next) {
	String bLastN = ((Person)next.getLastName();
	int comp = ((Person)this).getLastName().compareTo(bLastN);   	
	if (comp == 0) return 0;    //guess this is the only return statement that is 
	if (comp < 0) return -1;  //needed, but the 2 other doesn't seem to do
	else return 1;  	//any harm either
}
------------------------------------------

In class CardIndex:
public void sortItorScrewIt(){
   	Collections.sort(cInd);
}
säkki is offline   Reply With Quote