Solved

for loop with Set

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
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 …

758 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

20 Experts available now in Live!

Get 1:1 Help Now