Solved

for loop with Set

Posted on 2016-09-04
4
49 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
allswap challenge 6 96
Programatically extract date from website 8 77
replace a word with other 1 44
jdbc error in jsp application 20 44
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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 …
The viewer will learn how to implement Singleton Design Pattern in Java.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

813 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

15 Experts available now in Live!

Get 1:1 Help Now