What is difference between mutable and immutable String in java

Case 1: String str = “Good”; str = str + ” Morning”; In the above code you create 3 String Objects. “Good” it goes into the String Pool. ” Morning” it goes into the String Pool as well. “Good Morning” created by concatenating “Good” and ” Morning”. This guy goes on the Heap. Note: Strings … Read more

Should mutexes be mutable?

The hidden question is: where do you put the mutex protecting your class? As a summary, let’s say you want to read the content of an object which is protected by a mutex. The “read” method should be semantically “const” because it does not change the object itself. But to read the value, you need … Read more

What is the syntax for adding an element to a scala.collection.mutable.Map?

The point is that the first line of your code is not what you expected. You should use: val map = scala.collection.mutable.Map[A,B]() You then have multiple equivalent alternatives to add items: scala> val map = scala.collection.mutable.Map[String,String]() map: scala.collection.mutable.Map[String,String] = Map() scala> map(“k1”) = “v1” scala> map res1: scala.collection.mutable.Map[String,String] = Map((k1,v1)) scala> map += “k2” -> … Read more

Immutable/Mutable Collections in Swift

Arrays Create immutable array First way: let array = NSArray(array: [“First”,”Second”,”Third”]) Second way: let array = [“First”,”Second”,”Third”] Create mutable array var array = [“First”,”Second”,”Third”] Append object to array array.append(“Forth”) Dictionaries Create immutable dictionary let dictionary = [“Item 1”: “description”, “Item 2”: “description”] Create mutable dictionary var dictionary = [“Item 1”: “description”, “Item 2”: “description”] Append … Read more