Please I need a java expert to help me with the code and algorithm that deletes duplicate element from an array.
I have written a programm to do this as shown below using my own algpritm. Though it is working but I think my code is too long for this exercise. I am a beginner in Java. see code below;
Inline Code Example Here
public class ArrayDuplicateRemoval {
int [] rawArray = {1,2,3,1,2,3,4,4,2,1,2,1,5,1};
int [] newArray = new int [rawArray.length];
int countA = 0;
int countB = 0;
public static void main(String[] args) {
ArrayDuplicateRemoval dup = new ArrayDuplicateRemoval();
dup.feedArray();
dup.displayArray();
}
public void feedArray(){
if(countA < newArray.length){
removeDuplicate(rawArray[countB]);
}
}
public void removeDuplicate(int arrayElement){
for (int x:newArray)
if (arrayElement == x)
{
countA++;
countB++;
feedArray();
}
for (int m:newArray)
if ((m != arrayElement )&(countA < newArray.length))
{
newArray [countA] = arrayElement;
countA++;
countB++;
feedArray();
}
}
public void displayArray(){
System.out.println("Values in the raw array are listed below");
for(int k: rawArray)
System.out.printf(" %d", k);
System.out.println();
System.out.println("\nValues in the array after duplicate numbers are removed");
for(int c: newArray)
{
if( c != 0)
System.out.printf(" %d", c);
}
System.out.println();
}
}
Please help me with the shortest possible algorith that will perform the same function.
Thank you in advance.