{"id":1098,"date":"2019-02-12T11:58:30","date_gmt":"2019-02-12T06:28:30","guid":{"rendered":"http:\/\/blog.openwebsolutions.in\/?p=1098"},"modified":"2019-02-12T11:58:30","modified_gmt":"2019-02-12T06:28:30","slug":"how-declare-mutable-immutable-string-kotlin","status":"publish","type":"post","link":"https:\/\/openwebsolutions.in\/blog\/how-declare-mutable-immutable-string-kotlin\/","title":{"rendered":"How we can declare mutable and immutable string in Kotlin?"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p>In Kotlin whatever value you define here that determines the data types of the variable. Suppose (var myNumber =10),that automatically becomes integer value. Similarly, you can write the datatypes of the variable (var myString: String). In case of the mutable string, you can modify string at any point of time. Example of mutable &amp; immutable string-<\/p>\n<p>fun main(args: Array&lt;String&gt;) {<\/p>\n<p>var myString: String\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\/\/ Mutable String<br \/>\nmyString = &#8220;Hello World&#8221;<br \/>\nmyString = &#8220;Another World&#8221;<\/p>\n<p>val myAnotherString = &#8220;My Constant String&#8221;\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/\u00a0 Immutable String<\/p>\n<p>myAnotherString = &#8220;Arin&#8221;\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&#8230;&#8230;Error will be given in this line because Immutable String cannot be modified<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p><strong>String Interpolation :-<\/strong><\/p>\n<p>In Kotlin String interpolation process is little bit different from any other languages.Example-<\/p>\n<p>fun main(arg: Array&lt;String&gt;) {<\/p>\n<p>var rect = Rectangle()\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\/\/\u00a0 creating object of Rectangle class named rect<br \/>\nrect:length = 5<br \/>\nrect:breadth = 3<\/p>\n<p>print(&#8221; length = ${rect.length} and breadth = ${rect.breadth}. Area is ${rect.length * rect.breadth}&#8221;)<\/p>\n<p>}<\/p>\n<p>class Rectangle {<\/p>\n<p>var length: Int = 0<br \/>\nvar breadth: Int = 0<\/p>\n<p>}<\/p>\n<p><strong>Output :<\/strong><\/p>\n<p>length = 5 and breadth = 3. Area is 15<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; In Kotlin whatever value you define here that determines the data types of the variable. Suppose (var myNumber =10),that automatically becomes integer value. Similarly, you can write the datatypes of the variable (var myString: String). In case of the mutable string, you can modify string at any point of time. Example of mutable &amp; [&hellip;]<\/p>\n","protected":false},"author":35,"featured_media":1143,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[12,13,5],"tags":[33,43,87,14],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v14.8.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How we can declare mutable and immutable string in Kotlin?<\/title>\n<meta name=\"robots\" content=\"index, follow\" \/>\n<meta name=\"googlebot\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta name=\"bingbot\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/openwebsolutions.in\/blog\/how-declare-mutable-immutable-string-kotlin\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How we can declare mutable and immutable string in Kotlin?\" \/>\n<meta property=\"og:description\" content=\"&nbsp; In Kotlin whatever value you define here that determines the data types of the variable. Suppose (var myNumber =10),that automatically becomes integer value. Similarly, you can write the datatypes of the variable (var myString: String). In case of the mutable string, you can modify string at any point of time. Example of mutable &amp; [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/openwebsolutions.in\/blog\/how-declare-mutable-immutable-string-kotlin\/\" \/>\n<meta property=\"og:site_name\" content=\"Openweb Solutions Blog\" \/>\n<meta property=\"article:published_time\" content=\"2019-02-12T06:28:30+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/openwebsolutions.in\/blog\/wp-content\/uploads\/2019\/02\/logo-text.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2250\" \/>\n\t<meta property=\"og:image:height\" content=\"500\" \/>\n<meta name=\"twitter:card\" content=\"summary\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/openwebsolutions.in\/blog\/#website\",\"url\":\"https:\/\/openwebsolutions.in\/blog\/\",\"name\":\"Openweb Solutions Blog\",\"description\":\"Transforming ideas into reality\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/openwebsolutions.in\/blog\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/openwebsolutions.in\/blog\/how-declare-mutable-immutable-string-kotlin\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/openwebsolutions.in\/blog\/wp-content\/uploads\/2019\/02\/logo-text.png\",\"width\":2250,\"height\":500},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/openwebsolutions.in\/blog\/how-declare-mutable-immutable-string-kotlin\/#webpage\",\"url\":\"https:\/\/openwebsolutions.in\/blog\/how-declare-mutable-immutable-string-kotlin\/\",\"name\":\"How we can declare mutable and immutable string in Kotlin?\",\"isPartOf\":{\"@id\":\"https:\/\/openwebsolutions.in\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/openwebsolutions.in\/blog\/how-declare-mutable-immutable-string-kotlin\/#primaryimage\"},\"datePublished\":\"2019-02-12T06:28:30+00:00\",\"dateModified\":\"2019-02-12T06:28:30+00:00\",\"author\":{\"@id\":\"https:\/\/openwebsolutions.in\/blog\/#\/schema\/person\/990bda7c6fac1aa9c1ffde7745f42628\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/openwebsolutions.in\/blog\/how-declare-mutable-immutable-string-kotlin\/\"]}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/openwebsolutions.in\/blog\/#\/schema\/person\/990bda7c6fac1aa9c1ffde7745f42628\",\"name\":\"Arindam Kundu\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/openwebsolutions.in\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/1eea674a264b13f5b7c5895e36503137?s=96&r=g\",\"caption\":\"Arindam Kundu\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/posts\/1098"}],"collection":[{"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/comments?post=1098"}],"version-history":[{"count":4,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/posts\/1098\/revisions"}],"predecessor-version":[{"id":1144,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/posts\/1098\/revisions\/1144"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/media\/1143"}],"wp:attachment":[{"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/media?parent=1098"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/categories?post=1098"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/tags?post=1098"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}