I have an array of characters. I should remove any duplicate characters. I did comparison between the string elements with an array of alphabets. There is another array that acts as counter for any duplictae alphabet. If any character has been found for more than once, I should remove the duplicated character and shif the elements to left. Below is the code. I get error at the line with the comment. Java needs the left hand side of the assignment to be variable. Can you help?
import java.util.ArrayList;
import java.util.Scanner;
public class removeduplicate {
public static void main (String args[])
{
Scanner s=new Scanner(System.in);
String str="abbsded";
String myChars="abcdefghijklmnopqrstuvwxyz";
int[] myCounter=new int[26];
for (int i=0; i<str.length(); i++)
{
for(int j=0; j<myChars.length(); j++)
{
if(str.charAt(i)==myChars.charAt(j))
{
myCounter[j]++;
if (myCounter[j]>1)
{
System.out.println("duplication found in "+ str.charAt(i));
for(int h=i; h<str.length();h++)
{
//this line does not work.
str.charAt(h)=str.charAt(h-1);
}
}
}
}
}//end for
}
}