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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:44:21+00:00 2026-06-03T04:44:21+00:00

I was wondering if there is any way of ordering enum for different classes.

  • 0

I was wondering if there is any way of ordering enum for different classes. If for example, I have a fixed group of chemicals which react in different ways to other chemicals, some strongly, some weakly. I basically want to be able to switch up the order in which they are arranged depending on the chemical the group is supposed to react to(i.e depending on the class.). I do know that I am supposed to use Comparable but I am not sure how to do it. If I am not clear enough, leave a comment and I will explain further.

Thanks.

public static enum Chem {
    H2SO4, 2KNO3, H20, NaCl, NO2
};

So I have something that looks like that and I already know how each chemical would react to some other chemicals. I simply want to arrange the Chems based on the chemical it would be reacting with. That’s pretty much all I have.

  • 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-06-03T04:44:22+00:00Added an answer on June 3, 2026 at 4:44 am

    Implement different Comparator‘s ( see http://docs.oracle.com/javase/6/docs/api/java/util/Comparator.html )

    Comparator comparator1 = new Comparator<MyEnum>() {
    
      public int compare(MyEnum e1, MyEnum e2) {
         //your magic happens here
         if (...)
           return -1;
         else if (...)
           return 1;
    
         return 0;
      }
    };
    
    //and others for different ways of comparing them
    
    //Then use one of them:
    MyEnum[] allChemicals = MyEnum.values();
    Arrays.sort(allChemicals, comparator1); //this is how you sort them according to the sort critiera in comparator1.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am wondering is there any way to execute following shell script, which waits
I was wondering if there's any way to have a scipy.sparse.csc_matrix format for mlpy
I'm wondering if there is any way to specify for example tomorrow as date
I have read that grouping happens before ordering, is there any way that I
I am wondering is there any way we can test the font size/color of
Wondering if there is any way to get the lambda expressions that result from
Just wondering if there is any way to get the NS records in C#.
I was wondering if there was any way of grabbing a variable from the
I'm wondering if there's any way for a Rails asset to vary according to
I was wondering if there is any way to SELECT the first number that

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.