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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:47:02+00:00 2026-06-16T10:47:02+00:00

I have been trying to do this for a while now but i can

  • 0

I have been trying to do this for a while now but i can not do.

How can i change the default Ascending order to descending order?
Plus, is there anyother easy way i can sort the array?

HighScore[] highscorelist = new HighScore[10]; // An array of 10

void setup() {
  size(800, 600);

  // score.txt is:
  //10  -
  //0   -
  //0   -
  //3   b

  String rows[] = loadStrings("scores.txt");

  for (int i = 0; i < highscorelist.length; i ++ ) { // Initialize
    String[] pieces = split(rows[i], TAB);
    highscorelist[i] = new HighScore(parseInt(pieces[0]), pieces[1]);
  }
  Arrays.sort(highscorelist, new SortHighScore());
}

void draw() { 
  fill(0);
  textSize(18);
  text("High Scores", 360, 234);
  text("Name", 300, 260);
  text("Score", 460, 260);
  int x = 320;
  int y = 290;


  //Arrays.sort(highscorelist, new SortHighScore("score"));
  for (int i =0; i < 10; i++) {
    highscorelist[i].display(x, y, 150);
    y+=20;
  }
}


class HighScore {
  int score;
  String name;

  HighScore() {
  }

  HighScore(int tempscore, String tempname) {
    score = tempscore;
    name = tempname;
  }

  void display(int x, int y, int gapX) {
    text(score, x+gapX, y);
    text(name, x, y);
  }
}

class SortHighScore extends HighScore implements Comparator {

  SortHighScore() {
  }

  /*
    method which tells how to order the two elements in the array.
   it is invoked automatically when we call "Arrays.sort", and must be included in this class.
   */
  int compare(Object object1, Object object2) {

    // cast the objects to your specific object class to be sorted by
    HighScore row1 = (HighScore) object1;
    HighScore row2 = (HighScore) object2;


    // necessary to cast to Integer type when comparing ints
    Integer val1 = (Integer) row1.score;
    Integer val2 = (Integer) row2.score;

    // the "compareTo" method is part of the Comparable interface, and provides a means of fully ordering objects.
    return val1.compareTo(val2);
  }
}
  • 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-16T10:47:03+00:00Added an answer on June 16, 2026 at 10:47 am
    Arrays.sort(array,Collections.reverseOrder());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to figure this out for a while now, but every
Been trying to find this online for a while now. I have a SDL_Surface
I have been working on this problem for a while now. I am trying
I have been trying to figure this out for quite a while, but what
I have been trying to solve this problem for a while, but couldn't with
So I have been trying to figure this out for a while, but nothing
I've been trying to change my code for a while now and have failed
I have been looking to an answer to this for a while now but
I have been scratching my head on this for a while now but still
I have been trying to get this code to work for a while now

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.