Given a string, return the string with duplicate characters removed.
Utilisateur anonyme
This is for case insensitive strings: class Solution { public static void main(String[] args) { String word = "Fofobut1t1"; String noDup = stringReturner(word); System.out.println(noDup); } public static String stringReturner(String strUpper){ if(strUpper.length() == 0){ return null; } else if (strUpper.length() == 1){ return strUpper; } String str = strUpper.toLowerCase(); char[] a = str.toCharArray(); LinkedHashSet noDup = new LinkedHashSet (); for(int i = 0; i < a.length; i++){ noDup.add(a[i]); } String s = ""; for(int i = 0; i < noDup.size(); i++){ s += noDup.toArray()[i]; } return s; } }