Respuesta :

Answer:

import java.util.*;  

public class Create_set

{

   public static void main(String args[])

   {

       Set<Integer> hset = new HashSet<Integer>(); //creating set using hashset of Integer type

       hset.add(10); //add method add members to set

       hset.add(20);

       hset.add(30);

       hset.add(40);

       System.out.println(hset); //printing the set

       

   }

}

OUTPUT :

[20,40,10,30]

Explanation:

The above code is implemented through java language. First a collection object is created using Set interface. Then that interface is implemented using Hashset class. As they are of generic datatype, Integer type is declared for this object. Then using add() method elements of the set are added and at last they are printed.

Set is an unordered collection which means elements can't be accessed through their particular position and no duplicate values are stored in sets.