What is wrong in the code? Why does not it work? It is necessary to remove duplicates from the array.
public class Dublicate { public String[] delDublicate(String[] args) { StringBuffer result = new StringBuffer(); StringBuffer esult = new StringBuffer(); int i=1; for (int j=0; j <args.length; j++) { result.append(args[i]); String res = result.toString(); esult.append(args[j]); String re = esult.toString(); if (res.equals(re)){ if (args[j]!= args[i]) { args[i] = " "; } } } return args; } public static void main(String[] args){ String [] res={"Привет", "Привет", "задание", "выполнено", "верно", "задание"}; Dublicate dub=new Dublicate(); dub.delDublicate(res); System.out.print(Arrays.deepToString(res)); } }
int i = 1;what she does? You use it as a key to access the elements of the array, but you have it all the time 1. - XelaNimed