Adding an object to a scala list

I'm trying to add and put into the list is not just a number, so when you answer with an example, if you could use an object, for example, my used car or fruit or something else I looked every time, and all the examples that I see just add numbers to the list.
Im trying to convert some java code to scala java im code having conversion problems -

ArrayList usedCarList = new ArrayList();
UsedCars usedCar = new UsedCars();
usedCarList.add(usedCar);

Now I looked through a few examples, but they don't seem to work when I start trying to use an object, i.e.

var b = List[Int](); 
b ::= 1; 
b ::= 2; 
b ::= 3; 

I have tried several things that are listed below.

var usedCarList = List();
def addCar (usedCarList: List[UsedCars]){
var usedCar = new UsedCars();
series of set operations on the usedCar
usedCar :: usedCarList;
println(usedCarList.length);
}

when I check the size of the list, it is always empty

+5
source share
2 answers

Scala List Java ArrayList: Scala List .

- Java , . Scala a List -.

, , , "": b ::= 1. b = 1 :: b, . b. , , List - ( ).

, . Scala ArrayList - ArrayBuffer.

, . , , . , , , , .

+3

(, scala.collection.mutable.MutableList) (scala.collection.immutable.List). , , - , , ::, , . var , :

scala> import scala.collection._
import scala.collection._

scala> val list = mutable.MutableList[UsedCars]()
list: scala.collection.mutable.MutableList[UsedCars] = MutableList()

scala> list += new UsedCars()
res0: list.type = MutableList(UsedCars@4bfa79c8)

scala> list.size
res1: Int = 1

. .

+4

All Articles