Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3287306
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:28:42+00:00 2026-05-17T20:28:42+00:00

I have a LinkedList<Individual> where Individual is a class that has a field processorTime

  • 0

I have a LinkedList<Individual> where Individual is a class that has a field processorTime.
It is needed to sort this LinkedList (descending order) basing on a function estimate(processorTime) which returns integers.

Please, tell me how can I do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T20:28:42+00:00Added an answer on May 17, 2026 at 8:28 pm

    Check this guide here:

    http://leepoint.net/notes-java/data/collections/comparators.html

    Quotations from the site:

    The java.util.Comparator interface 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

    Pasted code:

    // File: arrays/filelist/Filelistsort.java
    // Purpose: List contents of user home directory.
    //          Demonstrates use of Comparators to sort the
    //          same array by two different criteria.
    // Author: Fred Swartz 2006-Aug-23  Public domain.
    
    import java.util.Arrays;
    import java.util.Comparator;
    import java.io.*;
    
    public class Filelistsort {
    
        //======================================================= main
        public static void main(String[] args) {
            //... Create comparators for sorting.
            Comparator<File> byDirThenAlpha = new DirAlphaComparator();
            Comparator<File> byNameLength   = new NameLengthComparator();
    
            //... Create a File object for user directory.
            File dir = new File(System.getProperty("user.home"));
            File[] children = dir.listFiles();
    
            System.out.println("Files by directory, then alphabetical");
            Arrays.sort(children, byDirThenAlpha);
            printFileNames(children);
    
            System.out.println("Files by length of name (long first)");
            Arrays.sort(children, byNameLength);
            printFileNames(children);
        }
    
        //============================================= printFileNames
        private static void printFileNames(File[] fa){
            for (File oneEntry : fa) {
                System.out.println("   " + oneEntry.getName());
            }
        }
    }
    
    
    ////////////////////////////////////////////////// DirAlphaComparator
    // To sort directories before files, then alphabetically.
    class DirAlphaComparator implements Comparator<File> {
    
        // Comparator interface requires defining compare method.
        public int compare(File filea, File fileb) {
            //... Sort directories before files,
            //    otherwise alphabetical ignoring case.
            if (filea.isDirectory() && !fileb.isDirectory()) {
                return -1;
    
            } else if (!filea.isDirectory() && fileb.isDirectory()) {
                return 1;
    
            } else {
                return filea.getName().compareToIgnoreCase(fileb.getName());
            }
        }
    }
    
    
    ////////////////////////////////////////////////// NameLengthComparator
    // To sort by length of file/directory name (longest first).
    class NameLengthComparator implements Comparator<File> {
    
        // Comparator interface requires defining compare method.
        public int compare(File filea, File fileb) {
            int comp = fileb.getName().length() - filea.getName().length();
            if (comp != 0) {
                //... If different lengths, we're done.
                return comp;
            } else {
                //... If equal lengths, sort alphabetically.
                return filea.getName().compareToIgnoreCase(fileb.getName());
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that extends the LinkedList class. Here's an excerpt of the
Let's say I have a class like this: class LinkedList { struct Node {
I have a LinkedList, where Entry has a member called id. I want to
I have a linked list that I want to sort part of, eg: std::sort(someIterator,
If I have an LinkedList of Employee objects... Each employee has a Name, and
I have two LinkedList objects that are always of the same size. I want
I have this class: public abstract class Directory { protected int id; protected File
I have a question about LinkedList<> . There are properties of this list First
I have a question regarding the LinkedList class in Java. I have a scenario
Let's say I have a list (EG: LinkedList<SomeObject> that contains elements ordered by a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.