How to remove an item from a list in Scala having only its index?
问题 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 回答1: Simply use val trunced = internalIdList.take(index) ++ internalIdList.drop(index + 1) This will also work if index is larger than the size of the list (It will return the same