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);
HashSet iterator() method in java
import java.util.HashSet;
import java.util.Iterator;
public class HashSetIteratorMethodExample
{
public static void main(String[] args)
{
HashSet<String> hs = new HashSet<String>();
hs.add("Welcome");
hs.add("hello");
hs.add("world");
hs.add("core");
hs.add("java");
System.out.println("HashSet values are: " + hs);
// create an Iterator
Iterator<String> value = hs.iterator();
System.out.println("iterator values are: ");
while(value.hasNext())
{
System.out.println(value.next());
}
}
}
set iteration java
import java.util.HashSet;
import java.util.Set;
class IterateHashSet{
public static void main(String[] args) {
Set<String> hset = new HashSet<String>();
hset.add("Chaitanya");
hset.add("Rahul");
for (String temp : hset) {
System.out.println(temp);
}
}
}
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