Write code to removes duplicate characters from the String
//package com.book2s; public class Main { public static void main(String[] argv) { String inputString = "book2s.com"; System.out.println(getUniqueCharString(inputString)); }//from w w w. j a v a 2 s .c om /*** * getUniqueCharString(final String inputString) * This method removes duplicate characters from the String * @param inputString * @return String */ public static String getUniqueCharString(final String inputString) { final char[] inputCharArray = inputString.toCharArray(); final int countChar[] = new int[59]; char[] outputArray = new char[inputCharArray.length]; int index = 0; for (char c : inputCharArray) { if (countChar[((int) c - 64)] == 1) { outputArray[index] = c; index++; } countChar[((int) c - 64)] = countChar[((int) c - 64)] + 1; } return charArraytoString(outputArray); } public static String charArraytoString(final char[] inputArray) { String finalResult = new String(); for (char c : inputArray) { if (c != '\u0000') { finalResult = finalResult + ((Character) c).toString(); } } return finalResult; } }