2

Is there any built-in function in Scala that takes a part of an array and creates a new array from this part? Something that makes the following pseudo-code:

newarr = oldarr[3:5]

meaning, newarr is an array of 3 elements, that:

newarr[0]=oldarr[3]
newarr[1]=oldarr[4]
newarr[2]=oldarr[5]
cchantep
  • 9,118
  • 3
  • 30
  • 41
CrazySynthax
  • 13,662
  • 34
  • 99
  • 183
  • 1
    Possible duplicate of [What is the correct way to get a subarray in Scala?](http://stackoverflow.com/questions/10830944/what-is-the-correct-way-to-get-a-subarray-in-scala) – Radu Oct 31 '16 at 14:45

1 Answers1

7
val newarr = oldarr.slice(3,6) // from index 3 until (not including) index 6

Study the Standard Library. It's amazing what you'll find there.

jwvh
  • 50,871
  • 7
  • 38
  • 64