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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:10:24+00:00 2026-05-13T07:10:24+00:00

I have an array in Scala with the class ArrayBuffer[Actor] , where Actor is

  • 0

I have an array in Scala with the class ArrayBuffer[Actor], where Actor is a class that implements the Ordered[Actor] trait. How do I sort this array without coding it manually?

I know there is an object called Sorting, but it doesnt seem to work since ArrayBuffer doesn’t implement/extend the right classes.

How do I sort ArrayBuffer[A] type arrays?

  • 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-05-13T07:10:24+00:00Added an answer on May 13, 2026 at 7:10 am

    If you are using Scala 2.8, you could use the sortWith method of the ArrayBuffer[T] class, which is inherited from the SeqLike trait.

    The following code snippet sorts an ArrayBuffer[T] object in ascending order:

    def ascendingSort[T <% Ordered[T]](xs: ArrayBuffer[T]) = xs.sortWith(_ < _)
    

    Note that this does not mutate the actual ArrayBuffer, but creates a new one with the elements in the right order.

    If you are using Scala 2.7, you could use the stableSort method of the Sorting object. This takes the elements of the ArrayBuffer and produces an array of elements sorted in the right order (given by a closure as an argument, ascending as a default).

    For example:

    val a = new scala.collection.mutable.ArrayBuffer[Int]()
    a += 5
    a += 2
    a += 3
    
    scala.util.Sorting.stableSort(a)
    

    The important question is what do you want to do with the ArrayBuffer. Usually, a Buffer is used internally in different algorithms in order to increase the performance of intermediate results. If you are using it for that, have a look at the ways of sorting the collection you want to return at the end of your algorithm. The Sorting object already provides a way of transforming an ArrayBuffer into a sorted Array.

    From the scaladoc of the Buffer class:

    Buffers are used to create sequences of elements incrementally

    As you are using it with Actors, it might be used for some kind of actor queue – in which case, you might want to have a look at the Queue collection.

    Hope it helps,

    — Flaviu Cipcigan

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

Sidebar

Ask A Question

Stats

  • Questions 269k
  • Answers 269k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer $image = ImageCreateFromString(file_get_contents('/path/to/image.ext')); ImageFilter($image, IMG_FILTER_GRAYSCALE); ImageGIF($image); // or ImagePNG($image); May 13, 2026 at 1:20 pm
  • Editorial Team
    Editorial Team added an answer Use ADAM (Windows Server 2003 Active Directory Application Mode) For… May 13, 2026 at 1:20 pm
  • Editorial Team
    Editorial Team added an answer you could query v$database: SQL> SELECT NAME FROM v$database; NAME… May 13, 2026 at 1:20 pm

Related Questions

I'm wondering if there is some way to unpack a variable length argument list
I have an 2 dimensional array. I write 3 values into the array during
I would like to store a mapping of an integer key to a float
I have an array that I want to permutate randomly. In Java, there is
Coming from OO (C#, Java, Scala) I value very highly the principles of both

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.