Set集合会将重复的键值过滤掉.利用这一特性.可以将数组里相同的字符串过滤掉.

代码:

    public static void main(String[] args) {
        String[] str 
= {"a""b""c""b""c""d","a"};
        Set
<String> set = new HashSet<String>();
        
// 将Collection追加到Set中
        set.addAll(Arrays.asList(str));
        
// 将Set转储到一个新分配的数组
        String[] result = set.toArray(new String[0]);
        
for(String str2: result){
            System.out.print(
"==>" + str2);
        }
    }

结果:

==>d==>a==>c==>b

 

 

相关文章:

  • 2021-09-16
  • 2021-12-07
  • 2021-10-27
  • 2021-08-03
  • 2022-12-23
  • 2021-07-15
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-30
  • 2021-05-16
  • 2022-12-23
  • 2021-06-09
  • 2022-12-23
  • 2022-02-09
相关资源
相似解决方案