将字符串转换为char数组,并将其存储在中
linkedHashSet。这样可以保留你的订购,并删除重复的商品。就像是:
String string = "aabbccdefatafaz";char[] chars = string.toCharArray();Set<Character> charSet = new linkedHashSet<Character>();for (char c : chars) { charSet.add(c);}StringBuilder sb = new StringBuilder();for (Character character : charSet) { sb.append(character);}System.out.println(sb.toString());
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)