思路:利用集合的contains方法将某个字符串中的集合中没有的单个字符添加到集合中,然后再将集合中每个元素做拼接

@Test
    public void aa5(){
        String aa="aabcdc";
        List<String> ls=new ArrayList<String>();
        for(int i=0;i<aa.length();i++){
            String s=aa.substring(i, i+1);
            if(!ls.contains(s)){
                ls.add(s);
            }
        }
        String result="";
        ls.toString();
        System.out.println(ls.toString());//[a,b,c,d]
        for (String s : ls) {
            result+=s;
        }
        System.out.println(result);//abcd
    }

 

相关文章:

  • 2022-12-23
  • 2022-02-07
  • 2021-07-18
  • 2022-12-23
  • 2022-12-23
  • 2021-12-25
  • 2021-10-22
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-01
  • 2022-01-27
  • 2022-01-07
  • 2021-05-23
  • 2021-07-13
  • 2022-12-23
相关资源
相似解决方案