Skip to main content

Java Comparator Applications

Java Comparator is one of the favourite questions in Java Interviews.

This concept looks deceptively simple, and slight variations of this could be asked in the interviews.


1) Write an AlphaNumeric Comparator in Java that sorts the given strings in the human readable
    format.

 e.g., file1, file2, file 3, file4, file 10

Not like the typical comparator file1, file10




2) Chained Comparator which can be used to join Multiple Comparators


3) Given a List of Employee Objects group the Objects such that all the employees are grouped by
    Department and by Name.


4) Use Java 8 Style Comparators




Comments

Popular posts from this blog

Data Structures using Java

package com.test.count; /**   *     * @author Kiran   *   */ public class LinkedList { Node headNode ; /** *   This method appends the Node at the end of the List *   * @param data */ public void appendNode( int data ) { Node currentNode = headNode ; if ( currentNode == null ) { Node newNode = new Node( data ); headNode = newNode ; return ; } while ( currentNode .getNextNode()!= null ) { currentNode = currentNode .getNextNode(); } currentNode .setNextNode( new Node( data )); } /** * This method prints all the Nodes/Values of the   * LinkedList *   */ public void printNodes() { Node currentNode = headNode ; if ( currentNode == null ) { System. out .println( " The Node is Null" ); return ; } else { System. out .print( "   " + currentNode .getData()); while ( currentNo...