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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:06:07+00:00 2026-06-14T13:06:07+00:00

Enum: public enum ComponentType { INSTRUCTION, ACTION, SERVICE, DOMAIN, INTEGRATION, OTHER, CONTEXT; } Class

  • 0

Enum:

 public enum ComponentType {
    INSTRUCTION, ACTION, SERVICE, DOMAIN, INTEGRATION,  OTHER, CONTEXT;
 }

Class A :

 public class A
 {
    String name;
    ComponentType c;
    public A(String name, ComponentType c)
    {
      this.name = name;
      this.c = c;
    }

 }   

Code:

 List<A> l = new ArrayList<A>();
 l.add(new A("ZY", ACTION));  
 l.add(new A("ZY0", INSTRUCTION));  
 l.add(new A("ZY1", DOMAIN));  
 l.add(new A("ZY2", SERVICE));  
 l.add(new A("ZY3", INSTRUCTION));  
 l.add(new A("ZY4", ACTION));  

How to sort list according to enum order?

  • 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-14T13:06:09+00:00Added an answer on June 14, 2026 at 1:06 pm

    You should simply delegate to the enum compareTo method which is already provided and reflects the declaration order (based on the ordinal value):

    Collections.sort(list, (a1, a2) -> a1.getType().compareTo(a2.getType()));        
    

    Or, if you think that the component type provides the “natural order” for your elements, you can make the A class itself implement Comparable and also delegate the compareTo method to the ComponentType one.

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

Sidebar

Related Questions

I have the following enum public enum myEnum { ThisNameWorks, This Name doesn't work
I have such enum: public enum PartnershipIndicator { VENDOR(VENDOR), COPARTNER(COPARTNER), BUYER(BUYER); String code; private
I have an enum: public enum Action { Remove=1, Add=2 } And a class:
My object: public class Account(){ private String accountName; private AccountType accountType; // enum //I
I've got the following enum: public enum myEnum { ONE(ONE), TWO(TWO); private String name;
Suppose I have this enum: public enum TestEnum { EXAMPLE, FURTHER_EXAMPLE, LAST_EXAMPLE } With
Given a class containing an enum: public class MyClass { public enum NestedEnum {
Lets say you have this enum: Public Enum ApplicationStatus <Foo(Active)> Active = 1 <Foo(Inactive)>
This is my enum: public enum DocumentTypes { [EnumMember] TYPE_1 = 1, [EnumMember] TYPE_2
I have this enum: public enum ContentKey { Menu = 0, Article = 1,

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.