假设我有一个(我认为是默认可变)数组[字符串]从字符串数组中删除第n个元素在斯卡拉
在斯卡拉我怎么能简单地删除第n个元素?
没有简单的方法似乎可用。
希望喜欢的东西(我做这件事):
def dropEle(n: Int): Array[T]
Selects all elements except the nth one.
n
the subscript of the element to drop from this Array.
Returns an Array consisting of all elements of this Array except the
nth element, or else the complete Array, if this Array has less than
n elements.
非常感谢。
您是否明白t他将需要N次复制(或移动元素),并且不会在O(1)中完成? –
费用不是问题,我宁愿使用另一个更高效的数据结构,但由于相互依赖性很大,我必须坚持这一点,我不喜欢强制 - spasiba bolshoi! –
它是否必须是一个数组?你不可能转换为List,做你需要的一切,然后转换回Array? –