Home  >  Article  >  Java  >  Implementation method of Java array deduplication

Implementation method of Java array deduplication

王林
王林forward
2023-05-06 15:46:081573browse

1. Loop comparison

Loop comparison to see if the value of each element is consistent. I won’t go into details about this, mainly the second method

2. Use hashSet to remove duplicates

HashSet is a set without duplicate elements, implemented by hashMap, unordered, and allows null, but only allows one null value. Paste the code below for personal testing.

public boolean checkIsRepeat(String[] arrs){
 
HashSet<String> hashSet = new HashSet<>();
for(int i = 0 ; i < arrs.length; i++){
hashSet.add(arrs[i].trim());
}
if(hashSet.size() == arrs.length){
return true;
}
return false;
}

What are the basic data types of java

The basic data types of Java are divided into:

1. Integer type, used to represent the data type of integer.

2. Floating point type, a data type used to represent decimals.

3. Character type. The keyword of character type is "char".

4. Boolean type is the basic data type that represents logical values.

The above is the detailed content of Implementation method of Java array deduplication. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete