# What is equivalent to splice in array of vectors?

**URL:** <https://discourse.processing.org/t/what-is-equivalent-to-splice-in-array-of-vectors/16629>\
**Category:** Beginners\
**Created:** [December 25, 2019, 12:16pm UTC](https://discourse.processing.org/t/what-is-equivalent-to-splice-in-array-of-vectors/16629 "2019-12-25T12:16:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ruchi](https://avatars.discourse-cdn.com/v4/letter/r/f475e1/32.png) [@Ruchi](https://discourse.processing.org/u/Ruchi)\
**Post date:** [December 25, 2019, 12:16pm UTC](https://discourse.processing.org/t/what-is-equivalent-to-splice-in-array-of-vectors/16629/1 "2019-12-25T12:16:57Z")

</div>

I want to add a pvector at a specific index in arraylist of vectors which already includes few vectors similar to splice function for array. Any idea how to go about this for vectors?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [December 25, 2019, 12:28pm UTC](https://discourse.processing.org/t/what-is-equivalent-to-splice-in-array-of-vectors/16629/2 "2019-12-25T12:28:08Z")

</div>

I assume that you mean Arraylist (not array)

you can use add() but with an index :

`add(int index, E element)`

Inserts the specified element at the specified position in this list.

see [https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html](https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html)

In the example below,

```auto
  list.add(1, new PVector (311, 111) );

```

is different from

```auto
  list.add(new PVector (311, 111) );

```

Sketch:

```auto

float angle1=0;

ArrayList<PVector> list=new ArrayList(); 

void setup() {
  size(1640, 860);

  list .add(new PVector (111, 111) );
  list .add(new PVector (311, 311) );
}

void draw() {
  background(0);

  //
  int i=0;
  for (PVector pv : list) {
    ellipse(pv.x, pv.y, 
      5, 5);
    fill(255); 
    text (i, pv.x+6, pv.y );
    i++;
  }
}

void mousePressed() {
  //

  list .add(1, new PVector (311, 111) );
}

```

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 26, 2019, 2:32am UTC](https://discourse.processing.org/t/what-is-equivalent-to-splice-in-array-of-vectors/16629/3 "2019-12-26T02:32:15Z")

</div>

> [@Ruchi](#):
>
> splice function for array

JS example  
[JavaScript Array splice vs slice - Stack Overflow](https://stackoverflow.com/questions/37601282/javascript-array-splice-vs-slice) ,

but please show us this function for  
JAVA Array,  
as i did not find it.

@Chrisir  
i find this ?add? very confusing in Processing:

 ![LIST_add](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/c/cf017165007f187edb960574afad5accb82db317.png)

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [December 26, 2019, 8:59am UTC](https://discourse.processing.org/t/what-is-equivalent-to-splice-in-array-of-vectors/16629/4 "2019-12-26T08:59:42Z")

</div>

> [@kll](#):
>
> JAVA Array,  
> as i did not find it.

There is a special array section in the reference

> **[splice() / Reference](https://processing.org/reference/splice_.html)**
>
> Inserts a value or an array of values into an existing array. The first two parameters must be arrays of the same datatype. The first parameter specifies the initial array to be modified, and the seco…
