Answers for "loop through set java"

2

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);
Posted by: Guest on March-18-2020
2

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);
     }
  }
}
Posted by: Guest on June-26-2020
0

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());
     }
  }
}
Posted by: Guest on June-26-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language