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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:21:23+00:00 2026-06-02T14:21:23+00:00

I am trying to sort an arrayList in two different ways, one by the

  • 0

I am trying to sort an arrayList in two different ways, one by the areas of the objects inside the arrayList, and two, by the name(shape1, shape2) of the objects in the arrayList. The objects look like this when I print them into a file: shape1: (points, radius, etc…) area = 0.0 and the shapes keep going. I tried looking at other asked questions that are similar but all answered using Collections.sort. I am not sure I am supposed to be using this method. Here’s some code I’m working with to give you an idea:

for (int i =0; i <shapes.size();i++){
    for (int j = 1; j<shapes.size(); j++){
        if (shapes.get(i).getShape().area() > shapes.get(j).getShape().area())
        {
            //
        }
        else
        {
            //
        }
    }
}

I’m not sure how I should go about doing this. Any pointers? For the sorting by name I have to use:

shapes.get(i).getName()
  • 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-02T14:21:25+00:00Added an answer on June 2, 2026 at 2:21 pm

    Since this is homework, I will not post any code.

    If you are not allowed to use Arrays.sort, you can implement Selection Sort – it is very simple, and you have the beginnings of it written in your code already. The idea is on each iteration of the outer loop on i to pick the smallest element in the segment from i to shapes.size() using the inner loop on j, and place that element at the i-th position of your array. Your inner loop should look like this:

    for(int j = i+1 ; j<shapes.size(); j++)
    //          ^--- this is what's changed
    

    Now based on your if condition you either swap j-th element with i-th, or keep it in place and move on.

    For sorting strings, use compareTo method in your if condition.

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

Sidebar

Related Questions

I'm trying to sort a HashMap in two ways. The default way: alphabetically by
Im trying to sort through an arraylist of objects by a particular value within
I'm trying to sort an ArrayList of custom items and get 'At least one
Trying to sort this array of objects according to (1) depth and (2) weight,
Trying to sort by this multidimensional array by screen name: //Looping through this for
I'm trying to sort some records in rails and I'm passing something like created_at
I'm trying to sort an ArrayList in my Android app, but its throwing an
I am trying to sort my ArrayList, but when I check the first item
I am trying to sort large inputs in the fastest way in ascending order.
I'm trying to sort a list of CLLocationDistance values by closest distance (ascending order).

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.