So I assume my issue has to do with what is going on under the hood, but I don’t understand why this doesn’t works:
scala> b = b :: "apple";
<console>:8: error: value :: is not a member of java.lang.String
but this does:
scala> b = "apple" :: b;
b: List[java.lang.String] = List(apple, pear)
Thanks.
Method names that end in
:are right associative, sob :: "apple"tries to call the::method on a String, which doesn’t exist.The normal strategy for appending things if you must use a
Listis to add things to the beginning thenreversethe result when you’re done. But as Rex says, using a Vector might be better.