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

Implementation method of Java array deduplication

王林
Release: 2023-05-06 15:46:08
forward
1601 people have browsed it

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;
}
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template