@riskycheng yes,if you use Set,you just need to compare the length of them,if nums contains any duplicates ,the length of Set will be reduced,so this is my code:

public class Solution {
public boolean containsDuplicate(int[] nums) {
Set<Integer> set=new HashSet<>();
for(Integer num:nums) set.add(num);
return !(set.size()==nums.length);
}
}