how to iterate hashset in java 8
Set<String> set = new HashSet<String>();
for (String s : set) {
System.out.println(s);
}
//Java 8:
set.forEach(System.out::println);
how to iterate hashset in java 8
Set<String> set = new HashSet<String>();
for (String s : set) {
System.out.println(s);
}
//Java 8:
set.forEach(System.out::println);
loop through set python
#Create a set
num_set = set([0, 1, 2, 3, 4, 5])
for n in num_set:
print(n)
iterate over a set in C++
//Method 1
// Iterate over all elements of set
// using range based for loop
for (auto& i : mySet)
{
cout << i << " , ";
}
//Method 2
// Iterate over all elements using for_each
// and lambda function
for_each(mySet.begin(), mySet.end(), [](const auto & str)
{
cout<<str<<", ";
});
//Method 3
set<string>::iterator it = mySet.begin();
// Iterate till the end of set
while (it != mySet.end())
{
// Print the element
cout << *it << ", ";
//Increment the iterator
it++;
}
set iteration java
import java.util.HashSet;
import java.util.Iterator;
class IterateHashSet{
public static void main(String[] args) {
HashSet<String> hset = new HashSet<String>();
hset.add("Chaitanya");
hset.add("Rahul");
Iterator<String> it = hset.iterator();
while(it.hasNext()){
System.out.println(it.next());
}
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us