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 6529941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:41:48+00:00 2026-05-25T09:41:48+00:00

Consider a collection consisting of enum types. Is there some library method min (or

  • 0

Consider a collection consisting of enum types. Is there some library method min (or max) which accepts this collection (or varargs) and returns the smallest/highest value?

EDIT: I meant the natural order of enums, as defined by their compare implementation of Comparable.

  • 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-25T09:41:49+00:00Added an answer on May 25, 2026 at 9:41 am

    Enums implement Comparable<E> (where E is Enum<E>) and their natural order is the order in which the enum constants are declared.
    You can use their default Comparable implementation to get the max and min constants as declared:

    public enum BigCountries {
        USA(312), INDIA(1210), CHINA(1330), BRAZIL (190);
    
        private int population;
    
        private BigCountries(int population) {
            this.population = population;
        }
    
    }
    

    Then you can use:

    BigCountries first = Collections.min(Arrays.asList(BigCountries.values())); // USA
    BigCountries last = Collections.max(Arrays.asList(BigCountries.values()));  //BRAZIL
    

    Probably, a faster way would be to use direct access to the array returned by the values() method:

    BigCountries[] values = BigCountries.values();
    System.out.println(values[0]); // USA;
    System.out.println(values[values.length-1]); // BRAZIL;
    

    Note that the parameter given to the enum has no effect in the ordering.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's consider the following example. Writing API which has public method which returns Collection
I have a method which should consider a collection of instances of a class
Consider this problem: I have a program which should fetch (let's say) 100 records
Consider this SharePoint site hierarchy: - Site Collection - Site1 - Subsite1 - AnotherSubsite1
Consider this snippet defining a trait for the state of a simulation, which a
It seems from experimentation that the collection expression is evaluated only once. Consider this
My unsafe method accepts a collection byte[] s. All of these byte[] s are
Consider the following collection. True False False False True True False False I want
Consider the Following object model (->> indicates collection): Customer->Orders Orders->>OrderLineItems->Product{Price} The app is focused
consider the following http request: GET /defects?group-by=priority I would like the returned collection(feed) of

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.