Java Program to find duplicate characters in a String?

Following is a Java example which deletes duplicate elements from a given string.


import java.util.Arrays;
import org.apache.commons.lang3.ArrayUtils;
public class DuplicateSample {
   public static void main(String args[]){
      String str = "malayalam";
      char[] myArray = str.toCharArray();

      for(int i=0; i<myArray.length-1; i++){
         for (int j=i+1; j<myArray.length; j++){
            if(myArray[i] == myArray[j]){
               myArray = ArrayUtils.remove(myArray, j);
      System.out.println("String value after deleting the duplicate values :"+Arrays.toString(myArray));


String value after deleting the duplicate values :[m, a, l, y]