Solved

for loop with Set

Posted on 2016-09-04
4
48 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
  • 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB6 Compile Compatibility Issue 4 89
custom annotations 9 31
Programatically extract date from website 8 66
why cannot we forward request once the response is committed 2 33
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
A short article about problems I had with the new location API and permissions in Marshmallow
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now