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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:27:07+00:00 2026-06-18T09:27:07+00:00

What is the different between + and ++ applying on a set? scala> val

  • 0

What is the different between + and ++ applying on a set?

scala> val set = Set[String]("a","b")
set: scala.collection.immutable.Set[String] = Set(a, b)

scala> set + "c"
res2: scala.collection.immutable.Set[String] = Set(a, b, c)

scala> set ++ "c"
res3: scala.collection.immutable.Set[Any] = Set(a, b, c)

The first return Set[String] while the second return Set[Any].
It looks like ++ is more general, but what exactly is the ++ additional value?

  • 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-18T09:27:08+00:00Added an answer on June 18, 2026 at 9:27 am

    If you look at the API doc for Set’s ++ method, you’ll see it takes a GenTraversableOnce

    scala> val c:GenTraversableOnce[Any] = "c"
    c: scala.collection.GenTraversableOnce[Any] = c
    

    That means that in this case:

    scala> set ++ "c"
    res3: scala.collection.immutable.Set[Any] = Set(a, b, c)
    

    "c" is a GenTraversableOnce[Any], and then the ++ method adds all the elements of that collection.

    A better example would be

    scala> set ++ "cd"
    res1: scala.collection.immutable.Set[Any] = Set(a, b, c, d)
    

    (I suspect like many other answerers I just did a little fiddling in the Scala console to check and then double-check whether that’s through an implicit conversion or not. Yes it appears it is.)

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

Sidebar

Related Questions

Is there any performance different between hosting your asp.net in mono on linux and
What are the different between this two diff statement? Any reference document? '{<table width=100%
Is there any different between NSString * str = @123; and NSString * str
I'm miss understanding what is the different between Layer7 or Layer4 applying load balancing.
Whats the different between Membership.GetUser and Profile.GetProfile if i wants to return a specific
Is there any different between declaring event Action<> and event EventHandler<> . Assuming it
I have set up transactional replication between two SQL Servers on different ends of
What is actually the different between those start processes ? I know the simple
What is the different between clearfix hack and overflow:hidden vs overflow:auto ? Are all
What's the different between var myObject : Sprite = new Sprite(); and var myObject

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.