Write a method count Unique that takes a List of integers as

Write a method count Unique that takes a List of integers as a parameter and returns the number of unique integer values in the list. Use a Set as auxiliary storage to help you solve this problem. For example, if a list contains the values [3, 7, 3, -1, 2, 3, 1, 2, 15, 15], your method should return 5. The empty list contains 0 unique values. Type your solution here: public static int countUnique(List list) {}

Solution

public static int countUnique(List<Integer> list)

{

Set<Integer> set=new HashSet<Integer>();

for(Integer i:list)

{

set.add(i);

}

return set.size();

}

 Write a method count Unique that takes a List of integers as a parameter and returns the number of unique integer values in the list. Use a Set as auxiliary st

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site