0
How to check the array elements is unique or not in java?
3 Answers
+ 3
// You can do it by converting the array into a set and by checking length of array and set are equal or not:
import java.util.*;
public class Qna {
public static void main(String[ ] args) {
Integer[] arr = {1,2,3,4,4};
Set<Integer> st = new HashSet<Integer>(Arrays.asList(arr));
System.out.print("Has Unique Elements? ");
System.out.println(arr.length==st.size()?true:false);
}
}
+ 2
loop through all of the element, then check one by one
0
See if you can understand
https://code.sololearn.com/craK7rp6av1H/?ref=app