Splice an ArrayList in Java similar to Node Js

Tags: , ,

In the Node Js code , we have the “stopTimeFrame()” method as below :

 public stopTimeFrame(timeFrameIdentifier: number): number {
    const startTimeStamp = this.timeFrames.splice(timeFrameIdentifier, 1)[0]

    return new Date().getTime() - startTimeStamp;

So, In Node Js code, they are using ‘Splice()’ method. I don’t have much knowledge on Node Js . So I just googled what is the usage of splice() in Node Js.

As per documentation (w.r.t the above code ), the splice() method adds new items at position ‘timeFrameIdentifier’ and remove 1 item.

I need to implement the similar method in Java . But I am not finding proper alternative to slice() in Java ?

Please Help


Splice method executed with 3 steps:

  • remove items
  • add new items
  • return removed items

So i think these above steps is not difficult to implement

Source: stackoverflow