How to remove an item from a list in Scala having

2020-02-09 07:22发布

I have a list as follows:

val internalIdList: List[Int] = List()

internalIdList = List(11, 12, 13, 14, 15)

From this list would remove the third element in order to obtain:

internalIdList = List(11, 12, 14, 15)

I can not use a ListBuffer, are obliged to maintain the existing structure. How can I do?

Thanks to all

7条回答
2楼-- · 2020-02-09 07:53

If you insist on using the oldschool method, use collect:

List(1,2,3,4).zipWithIndex.collect { case (a, i) if i != 2 => a }

However, I still prefer the method in my other answer.

查看更多
登录 后发表回答