题解 | #字符串去重#
字符串去重
http://www.nowcoder.com/practice/f105c85ed9d44469986d56c27920639e
Set集合不允许有重复元素
遍历字符串,添加到集合中
import java.util.HashSet; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String str = scanner.nextLine(); scanner.close(); HashSet<Character> hs = new HashSet<>(); //write your code here...... for(int i=0;i < str.length();i++){ hs.add(str.charAt(i)); } for (char c:hs) { System.out.print(c); } } }