Out of interest why does this work in Scala:
val exceptions = List[Char]('+')
assertTrue(exceptions.contains('+'))
but this not
val exceptions = new Array[Char]('+')
assertTrue(exceptions.contains('+'))
Following are the point of difference between lists and array in Scala: Lists are immutable whereas arrays are mutable in Scala. Lists represents a linked list whereas arrays are flat.
contains() function in Scala is used to check if a list contains the specific element sent as a parameter. list. contains() returns true if the list contains that element.
In a Scala list, each element need not be of the same data type.
Contains() ought to be around 50 nanoseconds. So the overall operation takes 50.05 microseconds. A faster Contains might take half the time, the overall operation takes 50.025 microseconds.
Because you wrote new ArrayChar. Doing that, the argument is the size of the array, and the '+' is, rather unfortunately, converted to an int to give the size. And the returned array is full of Char(0).
You should just do Array[Char]('+')
, '+'
would then be single element in the Array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With