# Delete an element by entering a number and the following elements must move up

**URL:** <https://discourse.processing.org/t/delete-an-element-by-entering-a-number-and-the-following-elements-must-move-up/20840>\
**Category:** Coding Questions\
**Created:** [May 13, 2020, 5:52pm UTC](https://discourse.processing.org/t/delete-an-element-by-entering-a-number-and-the-following-elements-must-move-up/20840 "2020-05-13T17:52:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![homeCoder](https://avatars.discourse-cdn.com/v4/letter/h/7feea3/32.png) [@homeCoder](https://discourse.processing.org/u/homeCoder)\
**Post date:** [May 13, 2020, 5:52pm UTC](https://discourse.processing.org/t/delete-an-element-by-entering-a-number-and-the-following-elements-must-move-up/20840/1 "2020-05-13T17:52:11Z")

</div>

This array element (e-mails) shows up when you start the program - thats right. But I want to do something like: If I press e.g. the key ‘1’ I want that the program delete automatically the mailingListe element number 1 (i=1) and the following elements must move up and replace the new blank space. I tried it the keyPressed command as you can see at the last lines but it didnt function. Does someone knows the right commands for this code.  
Thanks!

```auto
String [] mailingListe = new String[10];
int i,y;                                
PFont font;
String[] fontList = PFont.list();
String tmptext = "";

void setup()
{
  size(1000, 900);
  textSize(15);
  background(180);       
  fill(45);
  printArray(fontList);
  font = createFont("Times New Roman", 1);            
  textFont(font, 22);
  fillArray();
}

void draw()
{
     i=0;                               
     y=100;                              
     for (i=0; i<10; i++)                         
                                                
      {
         text(mailingListe[i],350,y);           
         y = y+70;                       
         
         text(tmptext, 350,y);
      }
}

void fillArray()
{
  mailingListe[0] = "test1@gmail.com";
  mailingListe[1] = "test2@gmail.com";
  mailingListe[2] = "test3@gmail.com";
  mailingListe[3] = "test4@gmail.com";
  mailingListe[4] = "test5@gmail.com";
  mailingListe[5] = "test6@gmail.com";
  mailingListe[6] = "test7@gmail.com";
  mailingListe[7] = "test8@gmail.com";
  mailingListe[8] = "test9@gmail.com";
  mailingListe[9] = "test10@gmail.com";
}

void keyPressed()        
                         
{
  if ( key == '1-9')      
  {
    mailingListe[i] = tmptext;  
    tmptext = " ";           
  } 
}

```

---

<div class="post-metadata">

**Author:** ![noahbuddy](https://avatars.discourse-cdn.com/v4/letter/n/73ab20/32.png) [@noahbuddy](https://discourse.processing.org/u/noahbuddy)\
**Post date:** [May 13, 2020, 10:32pm UTC](https://discourse.processing.org/t/delete-an-element-by-entering-a-number-and-the-following-elements-must-move-up/20840/2 "2020-05-13T22:32:37Z")

</div>

First, I am making the assumption that this was homework and that you were tasked with _implementing_ the function.  
If you are simply looking for a tool that does the job, that would be a different answer. 😁

Using keyPressed() is a nice way to do this, just remember that if your list is larger than 10 elements, you will have to change your solution.

Processing will not like comparing “key” to ‘1-9’ as that is not a ‘character’.  
What you can do is something like this:

```auto
// characters ("char" data type) can be compared numerically also
if ((key >= '0') && (key <= '9'))
{
  // manipulate array here
}

```

Hopefully that helps. Let us know if you get stuck again.

---

<div class="post-metadata">

**Author:** ![homeCoder](https://avatars.discourse-cdn.com/v4/letter/h/7feea3/32.png) [@homeCoder](https://discourse.processing.org/u/homeCoder)\
**Post date:** [May 19, 2020, 2:16am UTC](https://discourse.processing.org/t/delete-an-element-by-entering-a-number-and-the-following-elements-must-move-up/20840/3 "2020-05-19T02:16:06Z")

</div>

thank you for your helpful advice!
