Unit08A - Sets Sets Maps The Set and Map Interfaces 8A A...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
1 1 Sets & Maps The Set and Map Interfaces 8A 2 Sets A set is a collection of objects that contains no duplicates. The index of each element in the set is not important. The presence of the element is important. Set operations: Union A B Intersection A B Difference A - B Subset A B 3 Sets A = { 1, 2, 4, 8, 16, 32, 64 } B = { 1, 4, 9, 16, 25, 36, 49, 64 } (note: elements in the set are not necessarily stored in sorted order) A B = { 1, 2, 4, 8, 9, 16, 25, 32, 36, 49, 64 } A B = { 1, 4, 16, 64 } A - B = { 2, 8, 32 } A B = false 4 Sets in the Java API Collection AbstractCollection Set AbstractSet SortedSet HashSet TreeSet extends implements A A A Interface Abstract Class Concrete Class 5 Set<E> Interface boolean add(E item) Adds the specified item to this set if it is not already present. Returns true if the set has been changed, false otherwise. boolean addAll(Collection<E> coll) Adds all of the elements in the specified collection to this set without adding duplicates. Returns true if the set has been changed, false otherwise. boolean contains(Object obj) Returns true if this set contains the specified object, false otherwise. boolean containsAll(Collection <E> coll) Returns true if this set contains all of the objects in the specified collection, false otherwise. 6 Set<E> Interface boolean remove(Object obj) Removes the elements equal to the specified object if it is present. Returns true if the set has changed, false otherwise. boolean removeAll(Collection<E> coll) Removes all of the elements from this set that match elements of the specified collection. Returns true if the set has changed, false otherwise.
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern