S
S
S_C_R_E_A_M_E_R2019-08-28 17:40:23
Java
S_C_R_E_A_M_E_R, 2019-08-28 17:40:23

How to remove an array element in Processing?

How to remove an array element in Processing?
It is from the array "int[] integers = {1, 2, 3};" and not from "IntList integers = new IntList ();"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2019-08-28
@S_C_R_E_A_M_E_R

You can remove the last element

int[] removeNthElm(int[] array, int nElement)
{
  // перемещаем нужный элемент в конец
  for(int i = nElement - 1; i < array.length - 1; ++i)
  {
    // типа swap
    int a = array[i];
    array[i] = array[i + 1];
    array[i + 1] = a;
  }
  return shorten(array);
}

void draw() 
{
 int[] a = {1, 2, 3, 4, 5};
 a = removeNthElm(a, 1);
 printArray(a);
 exit();
}

OUT:
[0] 2
[1] 3
[2] 4
[3] 5

https://www.processing.org/tutorials/arrays/
https://www.processing.org/reference/Array

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question