Hello!
I was curious if i could help any guidance on my problem.
In my program i have the following class.

class Match{
    	String File;
    	String Area;
    	int Score = 0;
    	//public Match(int Index ){
    	public Match(String File,String Area, int Score){
    		this.Area = Area;
    		this.Score = Score;
    		this.File = File;
    	}
    	public String getArea(){
    		return Area;
    	}
    	public int Score(){
    		return Score;
    	}
    	public String getFile(){
    		return File;
    	}
    }

then i create an ArrayList of them.

ArrayList<Match> match = new ArrayList<Match>();

]

And get a number of entries.
I was curious if i could sort them out by the use of the

int Score

Any ideas on how to implement this or where should i refer to ?

Thanks in advance

See the API docs for the Comparator Interface (and google a tutorial or two) and then use the Collections.sort(List<T>, Comparator<T>) method.

masijade is right. If it's Python or Java, it's there you just have to find it. You might get lucky and it'll be built-in. Read the API.

You need to create a separate class "ClassSortsOnScore" or whatever you want to name it that implements comparable. After that its easy.

// here is an example
class SortsOnScore implements Comparator <Match>{
public int compare(Match one, Match two){
if (one.getScore()>two.getScore(){return -1;}
else if(one.getScore()==two.getScore()){return 0;}
else return 1;
}
}
}

Now after we have this comparator we just use it inside wherever we want to do the actions. To call it simply intantiate the class then pass it your array or w/e.

SortsOnScore sort1 = new SortsOnScore();
Collections.sort("array,or vector,or something else here",sort1);

We are not here to do peoples work for them. They learn much better when they actually do it themselves. Besides the fact that our own conduct rules here ask that you not do that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.