sort array java

import java.io.*;

import java.util.*;

public class Temp
{
    static BufferedReader keyboard = new
             BufferedReader(new InputStreamReader(System.in));

    public static void main(String[] args) throws IOException
       {
             int[] list = new int[20];


             IntClass length;

             int item;

             StringTokenizer tokenizer;


             System.out.println("Enter  12 integers in one line");

             tokenizer = new StringTokenizer(keyboard.readLine());

             for(int i = 0; i < 12; i++)
                list[i] = Integer.parseInt(tokenizer.nextToken());

             length = new IntClass(12);

             print(list, length.getNum());

             System.out.print("Enter item to be removed: ");
             System.out.flush();
             item = Integer.parseInt(keyboard.readLine());
             System.out.println();

             remove(list,length,item);

             print(list, length.getNum());
       }

       public static void remove(int[] list, IntClass len, int removeItem)
       {
             int i;

             int loc = 0;
             boolean found = false;


             if(len.getNum() == 0)
                   System.out.println("Cannot delete from an empty list");
             else
             {
                   for(i = 0; i < len.getNum(); i++)
                         if(removeItem == list[i])
                         {
                               found = true;
                               loc = i;
                               break;
                         }

                   if(found)
                   {
                         for(i = loc + 1; i < len.getNum(); i++)
                               list[i-1] = list[i];

                         len.setNum(len.getNum() - 1);
                   }
                   else
                         System.out.println(removeItem + " is not in the list");
             }
       }

       public static void print(int[] list, int len)
       {
             for(int i = 0; i < len; i++)
                   System.out.print(list[i] + " ");
             System.out.println();
       }
}

my question is if i want to find and delete all occurences of removeItem in the array
how my statments will be.
georges_nassarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MogalManicCommented:
The key to removing from an array, is to search BACKWARDS.  Like this:
  for(i = len.getNum(); i>0;i--) {
      if (list[i]==removeItem) {
          if (i<len.getNum()-1)  //Not already last item in the list
             System.arraycopy(list, i+1, list, i, len.getNum()-i);
          len.setNum(len.getNum() - 1); //Make list 1 item smaller
      }
  }

When each item is found, copy the tail end of the array over the item to be deleted and decrement the length by 1
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.