import java.util.*;
public class QuickCoding {
public static void main(String[] args){
int myArray[] = {1, 2, 3,5,1};
List list = new ArrayList();
for(int i=0;i<myArray.length;i++)
list.add(myArray[i]);
Set<Integer> set = new HashSet<Integer>(list);
if(set.size() < myArray.length){
System.out.println("There are some duplicates");
}
}
}
Muralidharan.E
Junior Poster in Training
74 posts since Apr 2008
Reputation Points: 32
Solved Threads: 7
Skill Endorsements: 0
@Muralidharan.E sorry, but your code is just de-tour from code posted by me. As you can see from above your for loop is not need it, if you use appropriate class to convert from collection (array) to collection(integers list) loop is obsolete.
peter_budo
Code tags enforcer
15,812 posts since Dec 2004
Reputation Points: 2,871
Solved Threads: 944
Skill Endorsements: 52
Set<Integer> set = new HashSet<Integer>(list);
Always set size is showing as 1. so i used loop without thinking. Now i will try to workout without loop.
Thank you Peter!
Muralidharan.E
Junior Poster in Training
74 posts since Apr 2008
Reputation Points: 32
Solved Threads: 7
Skill Endorsements: 0