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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:27:02+00:00 2026-06-04T16:27:02+00:00

I want to sort some objects which are in an ArrayList on the basis

  • 0

I want to sort some objects which are in an ArrayList on the basis of the objects properties.
the object has:

public class Minterm

{
    String minTerm;
    char flagTick;
    String minTermDerive;
    int groupNo;
    String adjGroup;
    static int MaxLiterals;

then i have this in the main method:

ArrayList<Minterm> column =new  ArrayList<Minterm>();

then i add some objects of type Minterm in the list. but at the end i want to organise them and sort them on the member variable groupNo(Ascending order).

i searched and came up with the comparable and comparator interfaces that i tried but didnt succeed. is there any other method to do this? or am i doing the comparator implemnting wrong.

EDIT :
Following is the code i wrote for Comparator. Please confirm if it will sort in ascending?

package backEnd;

import java.util.Comparator;

public class Comp implements Comparator<Minterm>
{
        @Override
        public int compare(Minterm a, Minterm b) 
        {
            return a.getgroupOne().compareTo(b.getgroupOne());
        }
}

i run it as:

Collections.sort(column , new Comp());

seems to be working fine. but i dont have a sound understanding of it.
Please confirm if it will sort in ascending?

  • 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-04T16:27:03+00:00Added an answer on June 4, 2026 at 4:27 pm

    You should let Minterm implement Comparable<MinTerm> or write a custom Comparator for MinTerm and then use Collections.sort.

    Using a comparator it would look like this:

    Collections.sort(column, new Comparator<Minterm>() {
        @Override
        public int compare(Minterm o1, Minterm o2) {
            return Integer.valueOf(o1.groupNo).compareTo(o2.groupNo);
        }
    });
    

    Regarding your edit:

    Yes. that sorts Minterms based on the groups in ascending order.

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

Sidebar

Related Questions

Hi I have an arrayList which has some objects.also my objects has two fields
I want to sort a String that has nr. How do I do that?
I have a class which has a String field called name . I have
I have an array of objects which I want to sort based on one
I have a simple NSArray which has some arrays as objects which has some
I have an ArrayList of objects (A class called OrderItem). OrderItem has a toString()
Lets say I want to sort some items and need to sort them by
I want to know how to add some sort of emblem or badge to
I want to use a shape of some sort for now, but would like
Introduction I have some sort of values that I might want to access several

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.