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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:42:36+00:00 2026-06-12T05:42:36+00:00

Is there a way to sort ints that are not in an array? I

  • 0

Is there a way to sort ints that are not in an array?

I know you can use sort(arrayList) type idea with an array but example…

If I have individual variables can a similar task be done? Example, if I have three numbers can I sort them so that they print from largest to smallest?

Thanks!

  • 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-12T05:42:37+00:00Added an answer on June 12, 2026 at 5:42 am

    If your ArrayList holds objects, the type of those objects can implement Comparable so you can use Collections‘ sort method. If you want, you can convert an ArrayList to an array and sort it that way, but it doesn’t look like that’s what you want. Here’s a quick example using both methods:

    void setup(){
      int count = 100,now;
      stroke(192,0,0);strokeWeight(count/width);
      //make up some data
      ArrayList<Pair> p = new ArrayList<Pair>();
      for(int i = 0 ; i < count ; i++) {
        Pair pair = new Pair(i,random(10,100));
        p.add(pair);
        float x = map(i,0,count,i,width);
        float y = map(pair.distance,10,100,0,50);
        line(x,50,x,50-y);
      }
    
      now = millis();
    
      //Sort typed ArrayList by converting to array first
      println("sort typed array: \n");
      Pair[] s = new Pair[p.size()];
      p.toArray(s);
      Arrays.sort(s);
    
      println("took " + (millis()-now) + " ms");
    
      now = millis();
    
      //Sort using Collections
      println("\n\nsorting typed array list: \n" );
      Collections.sort(p);
    
      println("took " + (millis()-now) + " ms");
    
      stroke(0,192,0);
      for(int i = 0 ; i < count ; i++) {
        Pair pair = p.get(i);
        float x = map(i,0,count,i,width);
        float y = map(pair.distance,10,100,0,50);
        line(x,100,x,100-y);
      }
    
    }
    class Pair implements Comparable<Pair>{
      public int id;
      public float distance;
      Pair(int i, float d){
        id = i;
        distance = d;
      }
      int compareTo(Pair p){
        if     (p.distance > this.distance) return  1;
        else if(p.distance < this.distance) return -1;
        else return 0;
      }
      String toString(){    return id+":"+distance;    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is there a way to automatically sort an observable array when a bound property
Is there any EASY way to sort an array in descending order like how
Is there a better way to shell sort using C#? // array of integers
is there a way in Scala to sort an array of tuples using and
Is there a way to sort the results by creation date? Example query which
Is there a way to sort an array using Chrome? Using the sort function
is there a way to sort an array and store the result in a
In Actionscript 3, is there a way to sort the nodes (instances of type
I need to sort an array of ints using a custom comparator, but Java's
Is there a way to sort an array of strings in alphabetical order where

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.