The basic difference between the set and the list is that set wont allow the duplicates the question is why cant we use original for loop for the set as we use for list
eg: length of set and list is same
for(int i =0 ; i< list.size;i++){
list.get(i);
set.get(i); // here it is throwing an error like get(index ) cant be applied for set
}
but if i use advance for loop(for each) its working
for(Object sample : set){
system.out.println(sample);
}
why is this happening ... is there any operational defference between for loop and for each , set and list ....
any help and suggestion would be useful ... thank you in advance