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

  • Home
  • SEARCH
  • 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 9183523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:49:29+00:00 2026-06-17T18:49:29+00:00

I have an arraylist of several items. An item may have a specific int

  • 0

I have an arraylist of several items. An item may have a specific int field LYING equal to OFF, FLOOR, RB1, RB2, RB3 or RB4.

For example OFF is defined as:

public static final int OFF = 0;

Regarding some specific global variables I would like to order those elements in a custom way, that may be for example:

  • all the RB1 items at the begin of the arraylist, all the RB2 items after any RB3 items (regardless the OFF items) and all the RB4 at the end of the arraylist.

Which is the best solution for my case?

Focusing on writing some custom:

public int compare(Object o1, Object o2) {
    if(globalVariable0 > 0) {
        if(o1.getLying() == o2.getLying)
            return 0;
        if(o1.getLying() == RB1 && o2.getLying != RB1)
            return -1;
        ...
    }else{
        ...
    }

or..?

  • 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-17T18:49:30+00:00Added an answer on June 17, 2026 at 6:49 pm

    There are probably several solutions for this but since we are talking about an “unnatural” order I’d hold an object with the correct order, for example a map that I can query for sortposition in my compare method, then the sortorder could be easy to edit in a properties-file maybe. Perhaps like this:

    public int compare(Object o1, Object o1){
      ActualType a1 = (ActualType) o1;
      ActualType a2 = (ActualType) o2;
      SortedOrderMap map = getSortOrderMap(); //cached of course
      Integer l1 = map.get(a1.getLying());
      Integer l2 = map.get(a2.getLying());
      return l1.compareTo(l2);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ArrayList of Timestamps. I want to split this ArrayList into several
I have an integer ArrayList and several buttons. Each button corresponds to an index
I have the following structure: List -->List_Participant -->Participant so a list may contain several
For my assignment, I have to develop several jUnit tests for the method: addAll(int
I have an ArrayList<MyObject> that may (or may not) contain duplicates of MyObject I
I have an options menu created and filled with several menu items. For some
I have arraylist myorderdata . I want to retrieve this arraylist to one String
At the moment inside the class I have ArrayList which the objects are stored
I have an arraylist called fetchContactName() which returns all names (31) in my contact
I have an ArrayList of HashMap like this: ArrayList<HashMap<String, String>> playListSongs = new ArrayList<HashMap<String,

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.