for loop with Set

Hi,

Since java collection Set interface do not support index can we still use for loop with them. I have been extensively using for loop with List not Set, Please advise
LVL 7
gudii9Asked:
Who is Participating?
 
Jeffrey DakeConnect With a Mentor Senior Director of TechnologyCommented:
While you can't loop through the pa directly you can call map.entryset() to get a set of Map.Entry objects which contain the key and value in the object.
0
 
Jeffrey Dake Senior Director of TechnologyCommented:
Yes, you can still loop through the values, but the order in which the elements will not be guaranteed to be in any order unless the set is an OrderedSet.
0
 
rrzConnect With a Mentor Commented:
I posted code demonstrating this at the bottom of my comment at  
https://www.experts-exchange.com/questions/28966735/commonTwo-challenge.html#a41786575
0
 
gudii9Author Commented:
oops i mean to say Map not set. Map do not have the index right? can we still use tradtional for loop like


for (int i=0; i<length; i++)

?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.