Re: Comparator and Comparable Programming Software Development by kumar.bhatia18 …persons.add(personOne); persons.add(personTwo); Collections.sort(persons, new Comparator() { @Override public int compare(Object o1, Object o2) … System.out.println(person2.getFirstName()); } } } For difference betweeen Comparator and Comparable you can visit my blog on java (http… Re: need help with this code Programming Software Development by vchandra … will you do that? here Comparable and Comparator interface comes in a picture. if you are… as per overridden method. read comparable and Comparator. if you are implementing Comparable then you … [CODE]import java.util.*; public class TableComparator implements Comparator<customerTable> { public int compare(customerTable x… Re: Location of element in an array Programming Software Development by mKorbel Comparator [url]http://www.java2s.com/Code/Java/Collections-Data-Structure/ListandComparators.htm[/url] Comparator Programming Software Development by nateuni …direction.. (if find the javadoc on the Comparator class is not very helpful) [code] public… class NameComparator implements Comparator { public static int compareNames(BankCustomer customerOne, BankCustomer …within my main class? I tried Comparator c = new Comparator(); and also all other combos.. but… Re: Comparator Programming Software Development by .11 You need this import [CODE] import java.util.Comparator;[/CODE] Then you need to implment this method, you dont … use it but since your implementing Comparator, you need to implement all the methods in Comparator. [CODE]@Override public int compare(Object… Re: Comparator Programming Software Development by JamesCherrill You use your comparator when you try to sort the array, for…, new NameComparator()); However, you haven't implemented the Comparator interface properly. You need your method to match the …, and return type EXACTLY to those defined in the Comparator, ie public int compare(BankCustomer customerOne, BankCustomer customerTwo); You… Re: Comparator Programming Software Development by nateuni …! Thanks again for your help! [code] public class NameComparator implements Comparator { @Override public int compare(Object ObjectOne, Object ObjectTwo) { //parameter are… Re: Comparator interfaces Programming Software Development by JamesCherrill … requires two methods (check out the Comparator API JavaDoc). Does your code compile? [QUOTE]a new …Constructor for the Club class that takes the Comparator<Player> parameter.[/QUOTE] Your constructor takes another …A Club object you should supply an instance of your Comparator that the Club object can use later for sorting its… Comparator interfaces Programming Software Development by scarletfire … [I]ComparePlayers[/I] class that implements the [I]Comparator<Player>[/I] interface. It should compare players…it. [CODE]import java.util.*; public class ComparePlayers implements Comparator<Player> { public int compare(Player ply1,… [I]Club[/I] class that takes the [I]Comparator<Player>[/I] parameter. What I wrote is… Re: Comparator interfaces Programming Software Development by scarletfire [QUOTE=JamesCherrill;1546302]1. The Comparator interface requires two methods (check out the Comparator API JavaDoc). Does your code compile? Your constructor takes… A Club object you should supply an instance of your Comparator that the Club object can use later for sorting its… Comparator and Comparable Programming Software Development by sk8ergirl … and I want to sort it using Comparator, but I don't know what is Comparator and when to use it. Also… Re: Comparator interfaces Programming Software Development by JamesCherrill You have been asked to pass an instance of your comparator to a constructor. Without actually doing your homework for you I showed you an example of passing an instance of String to a constructor. Understand how that works, and you will be able to write your own code. Re: Comparator and Comparable Programming Software Development by sk8ergirl … and how does this code work static class IntComparator implements Comparator<Person> { public int compare(Person o1, Person o2… Need Help with Comparable/Comparator. Programming Software Development by cool_whip579 …end CompareLastName[ICODE][/ICODE] class static class CompareFirstName implements Comparator <MyBooks>{ public int compare (MyBooks b1… compare } // end CompareFirstName class static class CompareTitle implements Comparator <MyBooks>{ public int compare (MyBooks b1, MyBooks… Re: Need Help with Comparable/Comparator. Programming Software Development by masijade [QUOTE=cool_whip579;1212274]Need Help with Comparable/Comparator.[/QUOTE] Good for you. I, however, have no idea what that needed help might be, since you didn't say/ask. Why is it safe not to override Object's equals() in a class implementing Comparator Programming Software Development by daudiam … method would return false. Am I right ? About the interface Comparator's equals, the API says that[QUOTE]Note that it…] but also says that [QUOTE]The ordering imposed by a Comparator c on a set of elements S is said to… too, why do we need the equals method in the Comparator interface ? Sorting ArrayList with a comparator, how to Programming Software Development by Violet_82 …; import java.util.Collections; import java.util.Comparator; import java.util.List; public class TestCollections …//Collections.sort(employeeCollection); // Sorting Collections.sort(employeeCollection, new Comparator<Employee>() { @Override public int compare(Employee … Re: Why is it safe not to override Object's equals() in a class implementing Comparator Programming Software Development by javaAddict … logic. The API says: "The ordering imposed by a Comparator c on a set of elements S is said to…] The API only said: "The ordering imposed by a Comparator c on a set of elements S is said to… Re: Hashmap, ArrayList and Comparator Programming Software Development by NormR1 … relationship between studentName and book.studentName? [QUOTE]i have a comparator function.. in the class:[/QUOTE] Can you explain what a… "comparator function" is? Java doesn't have functions. Where is… Re: Sorting ArrayList with a comparator, how to Programming Software Development by JamesCherrill …. Probabuy the nicest way to do this is to use `Comparator.comparing` with a Java 8 lambda eg Collections.sort(employeeCollection…, Comparator.comparing(Employee::getName)); (although personally I would be tempted to` … Hashmap, ArrayList and Comparator Programming Software Development by NewOrder … that array, and i want to sort the nodes using comparator<> interface (e.g. by name..) is it possible…? i have a comparator function.. in the class: [CODE]class Facebookfriends{ Facebookfriends info; String… Re: HashTable Comparator Programming Software Development by gangsta1903 your should create your comparator class by implementing Comparator Interface. Once you do it, then you can create your hashtable as follows: [code=java] private Hashtable<String, Planes> planesFlying = new Hashtable<String, Planes>(new YourMapComparator()); [/code] something similar to this. Re: HashTable Comparator Programming Software Development by javaAddict [QUOTE=gangsta1903;1151189]your should create your comparator class by implementing Comparator Interface. Once you do it, then you can create your … Re: Using Arrays.sort(Object[] , Comparator) for sorting a 2d array Programming Software Development by JamesCherrill … sub-array for the sort order. You can create a comparator that compares two Objects, and in it you cast the…[] and compare their first elements. You can then use that comparator to sort an array of arrays. ps Is your "… Re: Using Arrays.sort(Object[] , Comparator) for sorting a 2d array Programming Software Development by JamesCherrill …/java/java-object-sorting-example-comparable-and-comparator/ Section 4 (Sort an Object with Comparator) shows a decent example (but read 1… HashTable Comparator Programming Software Development by beforetheyknew …<String, Planes>();[/CODE] How can i write a comparator to sort this into alphabetical order? i've tried a… Re: HashTable Comparator Programming Software Development by gangsta1903 … TreeMap<String, Planes>(new MyComparator()); class MyComparator implements Comparator<String> { @Override public int compare(String o1, String… Using Arrays.sort(Object[] , Comparator) for sorting a 2d array Programming Software Development by abra_ka_dabra Can somebody explain me how to use Comparator class for sorting using Arrays.sort? I have a 2d array.. supoose i want to sort the array 4 by 4 (let us say) using column 1 of array(let us say)... Re: Using Arrays.sort(Object[] , Comparator) for sorting a 2d array Programming Software Development by abra_ka_dabra Yeah, i could get throught the read CSV file problem... I have marked it solved... Could you please give me an example of a code that use comparator class... ? I could better understand by that way... ` Rating Networks-A New Technology for Your Creation of Quick Designing and Fast Constr Programming Computer Science by waphon …comparators________operates comparator________assume device ________input values outputs________wire transmits comparator ________value outputs x' ________place same comparator________Wires … path ________values are shown etc________not same comparator ________operate network outputs ________connect data ________carry …