+ 1
mathematical set
for a code that is supposed to mimic a mathematical set...how do you make the set empty? is it public class Set (){ ... }
3 odpowiedzi
+ 1
Use the Set class from java.util.Set.
import java.util.Set;
Then in your code:
Set<Integer> set = new Set<Integer>();
This creates an empty set.
And if you want to empty the set mid-use, use set.clear(); as pointed out by Greg.
0
So you have a Set object. e.g. Set<String> set = new HashSet<String>(); if, after adding elements to the set you want it to be empty again, just call set.clear(); or assign the reference to a new empty set, i.e. set = new HashSet<String>();
0
greg can we have something like this Set <Interger> set = new HashSet <Integer>(); and now have
set.add (1); set.add (2); set.add (3);
and
set = Set <Integer> anotherSet ;
this way set has been assigned to another set object called "anotherSet"