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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:50:36+00:00 2026-06-06T01:50:36+00:00

scala> import scala.collection.mutable.Buffer import scala.collection.mutable.Buffer scala> val b = Buffer(1, 2, 3) b: scala.collection.mutable.Buffer[Int]

  • 0
scala> import scala.collection.mutable.Buffer
import scala.collection.mutable.Buffer

scala> val b = Buffer(1, 2, 3)
b: scala.collection.mutable.Buffer[Int] = ArrayBuffer(1, 2, 3)

scala> val l = List(1, 2, 3)
l: List[Int] = List(1, 2, 3)

scala> b == l
res1: Boolean = true

I was wondering, why the Buffer and List object can be compared with a result of true ?

I always thought, that because they are from different classes, they have to be false when compared. Can someone explain me, why it is implemented this way ?

  • 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-06T01:50:38+00:00Added an answer on June 6, 2026 at 1:50 am

    From http://www.scala-lang.org/docu/files/collections-api/collections_41.html

    The collection libraries have a uniform approach to equality and hashing. The idea is, first, to divide collections into sets, maps, and sequences. Collections in different categories are always unequal. For instance, Set(1, 2, 3) is unequal to List(1, 2, 3) even though they contain the same elements. On the other hand, within the same category, collections are equal if and only if they have the same elements (for sequences: the same elements in the same oder). For example, List(1, 2, 3) == Vector(1, 2, 3), and HashSet(1, 2) == Treeset(2, 1).

    It does not matter for the equality check whether a collection is mutable or immutable. (…)

    So it’s because scala.collection.mutable.Buffer and List belong to the same category (sequence) and equality is then defined as having equal elements.

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

Sidebar

Related Questions

I've written this basic program in Scala : import scala.collection.mutable.HashMap object HelloWorld { val
scala> val l = List((1,2), (2,3)) l: List[(Int, Int)] = List((1,2), (2,3)) I can
Using scala, 2.8: import scala.collection.mutable import mutable.MultiMap val m = new mutable.HashMap[String, mutable.Set[String]] with
Suppose I have import scala.collection.immutable.TreeMap val tree = new TreeMap[String, List[String]] Now after above
Can I use scala List in Java, like : import scala.collection.immutable.List; class HelloScalaList {
My code snippets are below import scala.collection.mutable.HashMap val crossingMap = new HashMap[String, Option[Long]] val
My code is as follows import scala.collection.mutable.HashMap type CrossingInterval = (Date, Date) val crossingMap
This can be done using a converter wrapper: import scala.collection.JavaConversions._ object ListConverter { def
he following compiles: import scala.collection.mutable.MutableList abstract class GeomBase[T <: DTypes] { val grids =
scala> val m = Map(1 -> 2) m: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2) scala>

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.