What is the output of the following code segments? Set<Integer> s = newHashSet<I
ID: 3610425 • Letter: W
Question
What is the output of the following code segments? Set<Integer> s = newHashSet<Integer>(); s.add(3); 1.System.out.println(s.add(7)); s.add(9); 2.System.out.println(s.add(3)); Iterator<Integer> i =s.iterator(); while(i.hasNext()); 3. System.out.print(i.next()); 1.____________ 2.____________ 3.____________ What is the output of the following code segments? Set<Integer> s = newHashSet<Integer>(); s.add(3); 1.System.out.println(s.add(7)); s.add(9); 2.System.out.println(s.add(3)); Iterator<Integer> i =s.iterator(); while(i.hasNext()); 3. System.out.print(i.next()); 1.____________ 2.____________ 3.____________Explanation / Answer
Dear,- A Set represents a mathematical set.
- It is a Collection that, unlike List, does not allowduplicates.
- There must not be two elements of a Set, say e1 and e2, suchthat e1.equals(e2).
- The add method of Set returns false if you try to add aduplicate element.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.