
hello,,
What is the Set interface?

hii,
The Set interface provides methods for accessing the elements of a finite mathematicalset. Sets do notallow duplicate elements.

Hi,
Here is the example of Set Interface in Java.
import java.util.*;
public class JavaSetExample
{
public static void main(String[] args)
{
System.out.println("Set Example in Java!");
// Create HashSet Object
Set set = new HashSet();
// Add elements to the HashSet object
set.add("Java");
set.add("JSP");
set.add("Servlet");
set.add("EJB");
set.add("JPA");
set.add("JSF");
//Iterate set
Iterator it = set.iterator();
while (it.hasNext()) {
//Get it
String element = (String)it.next();
System.out.println(element);
}
}
}
Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.