{"id":5594,"date":"2020-09-30T10:27:25","date_gmt":"2020-09-30T10:27:25","guid":{"rendered":"https:\/\/prwatech.in\/blog\/?p=5594"},"modified":"2024-04-11T07:12:48","modified_gmt":"2024-04-11T07:12:48","slug":"mutable-vs-scala-mutables-and-immutable-collections","status":"publish","type":"post","link":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/mutable-vs-scala-mutables-and-immutable-collections\/","title":{"rendered":"Scala &#8211; Mutable vs Immutable, REPL"},"content":{"rendered":"\r\n<h2 class=\"wp-block-heading\"><span data-sheets-root=\"1\" data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Scala - Mutables and Immutable Collections&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:6145,&quot;3&quot;:{&quot;1&quot;:0,&quot;3&quot;:1},&quot;14&quot;:{&quot;1&quot;:3,&quot;3&quot;:1},&quot;15&quot;:&quot;Arial&quot;}\">Scala &#8211; Mutables and Immutable Collections<\/span><\/h2>\r\n<p>&nbsp;<\/p>\r\n<p>In Scala, collections play a fundamental role in managing and processing data efficiently. Scala provides both mutable and immutable collections, offering developers flexibility in choosing the appropriate collection type based on their use case and performance requirements.<\/p>\r\n<p>Immutable collections in Scala are designed to be thread-safe and cannot be modified after creation. This immutability ensures predictable behavior and simplifies concurrency management in multi-threaded environments. Immutable collections include List, Set, Map, and others, and operations on these collections return new collections without modifying the original.<\/p>\r\n<h4><strong>Mutable vs Immutable:<\/strong><\/h4>\r\n\r\n\r\n\r\n<p class=\"has-medium-font-size\"><strong>Values<\/strong><\/p>\r\n\r\n\r\n\r\n<p>You can name the results of expressions with the\u00a0value keyword. Referencing a value doesn\u2019t re-compute it.<\/p>\r\n\r\n\r\n\r\n\r\n\r\n<p class=\"has-medium-font-size\"><strong>Variable<\/strong><\/p>\r\n\r\n\r\n\r\n<p>var keyword is use to define a variable. Variables are immutable. Variables are similar to values, except we can re-assign them.<\/p>\r\n\r\n\r\n\r\n\r\n\r\n<h4 class=\"wp-block-heading\"><strong>REPL (Read Evaluate Print Loop)<\/strong><\/h4>\r\n\r\n\r\n\r\n<p>The REPL is a command line interpreter <a href=\"https:\/\/www.tableau.com\/\">which<\/a> is use to test our <a href=\"https:\/\/prwatech.in\/blog\/scala\/scala-a-quick-overview\/\" target=\"_blank\" rel=\"noreferrer noopener\">Scala <\/a>code. It is simple to start a REPL session, just type\u00a0<code>Scala<\/code>\u00a0on your operating system command line and write a simple equation and the output will be:<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-gallery columns-1 is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\r\n<ul class=\"blocks-gallery-grid\">\r\n<li class=\"blocks-gallery-item\">\u00a0<\/li>\r\n<\/ul>\r\n<\/figure>\r\n\r\n\r\n\r\n<p>When we do not assign the result of our equation to any variable, the REPL automatically creates variable that start with the name\u00a0<code>res<\/code>. The output of variable is\u00a0stored in <code>res0<\/code>; the next one is stored in\u00a0<code>res1<\/code>, and so on.<\/p>\r\n\r\n\r\n\r\n\r\n\r\n<p class=\"has-normal-font-size\"><strong>REPL is also immutable, the reference example can be use as a reference<\/strong>.<\/p>\r\n<p>Scala &#8211; Mutables and Immutable Collections<\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>Scala &#8211; Mutables and Immutable Collections &nbsp; In Scala, collections play a fundamental role in managing and processing data efficiently. Scala provides both mutable and immutable collections, offering developers flexibility in choosing the appropriate collection type based on their use case and performance requirements. Immutable collections in Scala are designed to be thread-safe and cannot [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[565,1698],"tags":[934,933,935,936,937,941,938,939,940],"class_list":["post-5594","post","type-post","status-publish","format-standard","hentry","category-scala","category-scala-modules-scala","tag-immutable-in-scala","tag-mutable-in-scala","tag-mutable-vs-immutable-scala","tag-repl-scala","tag-scala-programming-functions","tag-use-of-variables","tag-values-and-variables-in-scala","tag-values-in-scala","tag-variables-in-scala"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Scala - Mutables and Immutable Collections - Prwatech<\/title>\n<meta name=\"description\" content=\"Master Scala - Mutables and Immutable Collections - Dive deep with our expert instructors and comprehensive curriculum.\" \/>\n<meta name=\"robots\" content=\"noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Scala - Mutables and Immutable Collections - Prwatech\" \/>\n<meta property=\"og:description\" content=\"Master Scala - Mutables and Immutable Collections - Dive deep with our expert instructors and comprehensive curriculum.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/mutable-vs-scala-mutables-and-immutable-collections\/\" \/>\n<meta property=\"og:site_name\" content=\"Prwatech\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prwatech.in\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-09-30T10:27:25+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-11T07:12:48+00:00\" \/>\n<meta name=\"author\" content=\"Prwatech\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:site\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prwatech\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/mutable-vs-scala-mutables-and-immutable-collections\/\",\"url\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/mutable-vs-scala-mutables-and-immutable-collections\/\",\"name\":\"Scala - Mutables and Immutable Collections - Prwatech\",\"isPartOf\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#website\"},\"datePublished\":\"2020-09-30T10:27:25+00:00\",\"dateModified\":\"2024-04-11T07:12:48+00:00\",\"author\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\"},\"description\":\"Master Scala - Mutables and Immutable Collections - Dive deep with our expert instructors and comprehensive curriculum.\",\"breadcrumb\":{\"@id\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/mutable-vs-scala-mutables-and-immutable-collections\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/mutable-vs-scala-mutables-and-immutable-collections\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/mutable-vs-scala-mutables-and-immutable-collections\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/prwatech.in\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Scala &#8211; Mutable vs Immutable, REPL\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/prwatech.in\/blog\/#website\",\"url\":\"https:\/\/prwatech.in\/blog\/\",\"name\":\"Prwatech\",\"description\":\"Share Ideas, Start Something Good.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/prwatech.in\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\",\"name\":\"Prwatech\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"caption\":\"Prwatech\"},\"url\":\"https:\/\/prwatech.in\/blog\/author\/prwatech123\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Scala - Mutables and Immutable Collections - Prwatech","description":"Master Scala - Mutables and Immutable Collections - Dive deep with our expert instructors and comprehensive curriculum.","robots":{"index":"noindex","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"en_US","og_type":"article","og_title":"Scala - Mutables and Immutable Collections - Prwatech","og_description":"Master Scala - Mutables and Immutable Collections - Dive deep with our expert instructors and comprehensive curriculum.","og_url":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/mutable-vs-scala-mutables-and-immutable-collections\/","og_site_name":"Prwatech","article_publisher":"https:\/\/www.facebook.com\/prwatech.in\/","article_published_time":"2020-09-30T10:27:25+00:00","article_modified_time":"2024-04-11T07:12:48+00:00","author":"Prwatech","twitter_card":"summary_large_image","twitter_creator":"@Eduprwatech","twitter_site":"@Eduprwatech","twitter_misc":{"Written by":"Prwatech","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/mutable-vs-scala-mutables-and-immutable-collections\/","url":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/mutable-vs-scala-mutables-and-immutable-collections\/","name":"Scala - Mutables and Immutable Collections - Prwatech","isPartOf":{"@id":"https:\/\/prwatech.in\/blog\/#website"},"datePublished":"2020-09-30T10:27:25+00:00","dateModified":"2024-04-11T07:12:48+00:00","author":{"@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3"},"description":"Master Scala - Mutables and Immutable Collections - Dive deep with our expert instructors and comprehensive curriculum.","breadcrumb":{"@id":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/mutable-vs-scala-mutables-and-immutable-collections\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/mutable-vs-scala-mutables-and-immutable-collections\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/mutable-vs-scala-mutables-and-immutable-collections\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/prwatech.in\/blog\/"},{"@type":"ListItem","position":2,"name":"Scala &#8211; Mutable vs Immutable, REPL"}]},{"@type":"WebSite","@id":"https:\/\/prwatech.in\/blog\/#website","url":"https:\/\/prwatech.in\/blog\/","name":"Prwatech","description":"Share Ideas, Start Something Good.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/prwatech.in\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3","name":"Prwatech","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","caption":"Prwatech"},"url":"https:\/\/prwatech.in\/blog\/author\/prwatech123\/"}]}},"_links":{"self":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/5594","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/comments?post=5594"}],"version-history":[{"count":8,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/5594\/revisions"}],"predecessor-version":[{"id":11341,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/5594\/revisions\/11341"}],"wp:attachment":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/media?parent=5594"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/categories?post=5594"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/tags?post=5594"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}