Thursday, 15 October 2015

Hashset example in java (using for-each loop)

import java.util.*;
public class First {

public static void main(String[] args) {
// TODO Auto-generated method stub
HashSet<String> hs = new HashSet<String>();
hs.add("Digital");
hs.add("India");
hs.add("Hello");
hs.add("World");
for(String st: hs){
System.out.println("The string value is " +st);
}

}

}


output:-
The string value is Hello
The string value is Digital
The string value is World
The string value is India

No comments:

Post a Comment