UsingCollection_Part1 - Copy.pdf

UsingCollection_Part1 - Copy.pdf - Using Collection...

  • No School
  • AA 1
  • 20

This preview shows page 1 - 7 out of 20 pages.

Using Collection Framework Part 1
Image of page 1

Subscribe to view the full document.

2 What is Data Structure? A data structure is a collection of data organized in some fashion. The structure not only stores data, but also supports operations for accessing and manipulating the data. A collection is a container object that holds a group of objects, often referred to as elements . The Java Collections Framework supports three types of collections, named lists , sets , and maps . Java Collection Framework hierarchy
Image of page 2
Java Collection Framework hierarchy, cont. Set and List are sub interfaces of Collection. 3
Image of page 3

Subscribe to view the full document.

More than just Lists… ArrayList s and LinkedLists are just two of the many classes comprising the Java Collections Framework (JCF) A collection is an object that maintains references to others objects Essentially a subset of data structures JCF forms part of the java.util package and provides: Interfaces Each defines the operations and contracts for a particular type of collection (List, Set, Queue, etc) Idea: when using a collection object, it’s sufficient to know its interface Implementations Reusable classes that implement above interfaces (e.g. LinkedList, HashSet) Algorithms Useful polymorphic methods for manipulating and creating objects whose classes implement collection interfaces Sorting, index searching, reversing, replacing etc. 4
Image of page 4
Interfaces 5 Root interface for operations common to all types of collections Specialises collection with operations for FIFO and priority queues. Stores a sequence of elements, allowing indexing methods A special Collection that cannot contain duplicates. Special Set that retains ordering of elements. Stores mappings from keys to values Special map in which keys are ordered Generalisation Specialisation Collection Set List Queue SortedSet Map SortedMap
Image of page 5

Subscribe to view the full document.

Expansion of contracts 6 + add (E):boolean + remove (Object):boolean + contains (Object):boolean + size ():int + iterator ():Iterator<E> etc… <<interface>> Collection<E> + add (E):boolean + remove (Object):boolean + get (int):E + indexOf (Object):int + contains (Object):boolean + size ():int + iterator ():Iterator<E> etc… <<interface>> List<E> + add (E):boolean + remove (Object):boolean + contains (Object):boolean + size ():int + iterator
Image of page 6
Image of page 7

{[ snackBarMessage ]}

Get FREE access by uploading your study materials

Upload your study materials now and get free access to over 25 million documents.

Upload now for FREE access Or pay now for instant access
Christopher Reinemann
"Before using Course Hero my grade was at 78%. By the end of the semester my grade was at 90%. I could not have done it without all the class material I found."
— Christopher R., University of Rhode Island '15, Course Hero Intern

Ask a question for free

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