Solved

for loop with Set

Posted on 2016-09-04
4
51 Views
Last Modified: 2016-09-08
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
0
Comment
Question by:gudii9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 10

Expert Comment

by:Jeffrey Dake
ID: 41784224
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
 
LVL 27

Assisted Solution

by:rrz
rrz earned 250 total points
ID: 41788844
I posted code demonstrating this at the bottom of my comment at  
https://www.experts-exchange.com/questions/28966735/commonTwo-challenge.html#a41786575
0
 
LVL 7

Author Comment

by:gudii9
ID: 41788941
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
 
LVL 10

Accepted Solution

by:
Jeffrey Dake earned 250 total points
ID: 41789031
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

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about problems I had with the new location API and permissions in Marshmallow
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question