Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


Anu Sunny
comparator
1 Answer(s)      3 years and 6 months ago
Posted in : Java Interview Questions


what is a comparator


Advertisement
View Answers

January 31, 2011 at 11:10 AM


Hi Friend,

A comparator is an interface that can be used to create objects to pass to sort methods or sorting data structures. A Comparator must define a compare function which takes two Objects and returns a -1, 0, or 1.

Thanks



Related Tutorials/Questions & Answers:
comparator
comparator  what is a comparator   Hi Friend, A comparator is an interface that can be used to create objects to pass to sort methods or sorting data structures. A Comparator must define a compare function which takes
Java Comparator Example
Java Comparator Example  Can you provide me an example of Comparator Interface?   A comparator object is capable of comparing two different...; } } class AgeComparator implements Comparator{ public int compare(Object ob1
Advertisements
collections2
collections2  when exactly we go for Comparator and when exactly we go for Comparable while sorting
java question
java question  comparator and comparable   Differences... a comparator object is capable of comparing two different objects. b... its instances while the Comparator class does not compare its instances
java question
java question  what r the Comparator vs Comparable   ... object while a comparator object is capable of comparing two different objects. b... to compare its instances while the Comparator class does not compare its
Java Of Sailendra - Java Interview Questions
Java Of Sailendra  Whats the use of comparator interface? How can we access the elements of a collection?   Hi Friend, Comparator... a class needs to implement Comparator or Comparable interface. For more
collection
while Comparator is used for custom ordering. 2)Comparable interface has compareTo() method which is used for natural ordering while Comparator interface has
Programming - WordFrequency modifications
that specifies a Comparator so it knows how to sort them, and add entry set from the HashMap... the previous part running, change the Comparator near the end of the file... frequent words are last. You'll need to change the Comparator for this. See line
collections
collections  1.Create an ArrayList of Object Planet with instance variable name and colour. Add 5 planets to the ArrayList planetList. Sort the ArrayList in ascending order of name and descending order of colour using comparator
collections
collections  1.Create class Dog with instance variable breed and height. Create 5 instances of Dog and add it to the Treeset dogSet. The Treeset should be in sorted order of height using a Comparator interface. Iterate through
Comparators
. A Comparator must define a compare function which takes two Objects... also has a predefined comparator for case insensitive sorting, String.CASE..."); Arrays.sort(children, fileComp); // Sort using a comparator. for (File
Comparators
. A Comparator must define a compare function which takes two Objects... also has a predefined comparator for case insensitive sorting, String.CASE..."); Arrays.sort(children, fileComp); // Sort using a comparator. for (File
Collections Class
; Comparator comp; Object key; Object obj; Collection coll...) Sorts list using Comparator.  shuffle(list... for key using Comparator comp. Returns index of element
Java latest file
modified file, we have used the Comparator interface that compare the files ... Comparator() { public int compare(File f1, File f2) { return Long.valueOf...()); } } In the above code, we have used Comparator Interface that compare
core java - Java Beginners
and comparator i want with source code with example... // Signature of compareTo method To sort a collection using a Comparator class... - that parameter being an instance of a Comparator object. Thus: Collections.sort(aList
java - Java Beginners
= f.listFiles(); Arrays.sort(files, new Comparator(){ public int compare(File f1
Java: Collections Class
).  sort(listT, comp) Sorts listT using a comparator..., key, comp) Searches in list for key using Comparator comp... in the Collection coll using Comparator comp. t =min(coll
collec
collec  actually both comparator and comparable interfaces are using for sorting, when exactly we go for comparator and when exactly we go.... A comparator object is capable of comparing two different objects. TheComparator
Arrange strings according to their length
comapare() of Comparator interface compare the length of all the strings. All... java.util.*; class Arrange implements Comparator { public int compare
Java read latest file
the Comparator interface that compare the files and by using the Arrays.sort() method, we... = f.listFiles(); Arrays.sort(files, new Comparator() { public int compare
Difference between sorted and ordered collection in hibernate
database using java comparator. If your collection is not large, it will be more
Java Collection : TreeSet Example
or by the comparator. Since it provides fast access and fast retrieval so... constructor - TreeSet(), TreeSet(Collection c), TreeSet(Comparator c... if it is in the set. Other  methods are - clear(), clone(), comparator(), contains
Core Java Doubts - Java Beginners
is the difference between comparable and comparator? 4)When we go... is capable of comparing itself with another object while a comparator object... the Comparator class does not compare its instances, but some other class?s
JAVA - Java Beginners
++; } Arrays.sort(data); List l=Arrays.asList(data); Comparator comparator = Collections.reverseOrder(); Collections.sort(l,comparator
Java: Sets
comp = sset.comparator() Returns Comparator used to compare elements... will be ordered by that, but often you will supply a Comparator object... TreeSet using Comparator comp to sort elements. tset = new TreeSet(coll
java
; } } class FNameComparator implements Comparator{ public int compare(Object... Comparator{ public int compare(Object emp1, Object emp2){ String... IdComparator implements Comparator{ public int compare(Object ob1, Object
Example - Read Words
a different layout. Comparator. Because Strings have a natural alphabetic sorting order, the Collections.sort() method doesn't need a Comparator for alphabetizing words. Sorting by word length will require writing a simple Comparator
Coffee shop
(){ return price; } } class NameComparator implements Comparator... name1.compareTo(name2); } } class PriceComparator implements Comparator{ public
Tree Set Example
. Comparator interface is used to alter the ordering.  TreeSet uses methods...;to remove all the element in this set, comparator() used to order the element
Sorting Arrays
into ascending order, using the Comparator comp. Arrays.sort... into ascending order using the Comparator comp... compareTo() method), can be sorted with using a comparator. The Arrays.sort
Collections (Data Structure Library)
Comparator RandomAccess // Marker interface java.util.Collections Class static methods binarySearch(List, Object) binarySearch(List, Object, Comparator...) max(Collection) min also max(Collection, Comparator) min also
DNA sequence - Java Beginners
(data); List l=Arrays.asList(data); Comparator comparator = Collections.reverseOrder(); Collections.sort(l,comparator); File file = new File("C
java - Java Beginners
++; } Arrays.sort(data); List l=Arrays.asList(data); Comparator comparator = Collections.reverseOrder(); Collections.sort(l,comparator
java - Java Beginners
); Comparator comparator = Collections.reverseOrder(); Collections.sort(l,comparator); File file = new File("C:/new.txt"); FileWriter fw = new
SortedMap (interface) example in java Collection Framework
according to the keys' natural order, or according to a Comparator provided... map. Comparator access: Returns the Comparator used to sort the map (if any
Set<E> interface
comp = sset.comparator() Returns Comparator used to compare..., String) elements will be ordered by that, but often you will supply a Comparator... TreeSet<E>(comp) Creates new TreeSet using Comparator comp to sort elements
Java Programming: Section 12.4
are used in a related context in Exercise 12.5. Using a Comparator... of a map. This is a typical use for a Comparator. Recall that a Comparator is an object that implements the Comparator interface and defines the method
java.util - Java Interview Questions
and interfaces in utility package are:Interfaces* Collection* Comparator* Enumeration
Sorting Array List in Java
the element increased. This example will explain sorting of ArrayList using Comparator
Java: Maps
comp = comparator() Returns Comparator used to compare keys. null...) this is ok, but often you will supply a Comparator object that tells how two keys.... tmap = new TreeMap(comp) Creates new TreeMap using Comparator comp
Java: Maps
comp = comparator() Returns Comparator used to compare keys. null...) this is ok, but often you will supply a Comparator object that tells how two keys.... tmap = new TreeMap(comp) Creates new TreeMap using Comparator comp
Java Sorting
getVote() { return vote; } } class VoteComparator implements Comparator... Comparator{ public int compare(Object can1, Object can2){ int vote1
cofee shop
; } } class NameComparator implements Comparator{ public int...(name2); } } class PriceComparator implements Comparator{ public int compare
Xcarecrows 4 XML
; a graphical XML tree comparator ; a built-in checker against XML Schemas ; an XSL... comparator, it handles the core editing functions available to the user. To further
Retrieve a list of words from a website and show a word count plus a specified number of most frequently occurring words
*/ /**ADD CODE * * Create a comparator... * * Then sort the array/list using this comparator
nikesh
; } public int getSalary(){ return salary; } } class NameComparator implements Comparator
arraylist
; } } class SalaryComparator implements Comparator{ public int compare(Object
JDK 8 Release Candidates Available
. This release includes the fixing of a flaw in the new Comparator API. The new
Generic Tags
iterators. sort: sorts a List using a Comparator subset: tag takes
 

 

 

DMCA.com