mathematical set | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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 (){ ... }

7th Sep 2016, 10:21 PM
Lesley
3 Answers
+ 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.
7th Sep 2016, 10:42 PM
Zen
Zen - avatar
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>();
7th Sep 2016, 10:39 PM
Greg Sims
Greg Sims - avatar
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"
2nd Oct 2016, 10:44 AM
tunde