Common Data Structures
Common Data Structures Mini Report Hien Vu 4/15/2014 ArrayList Linked List Hash Map Hash Set 1 • ArrayLi st Remind: Array 1 • ArrayLi st Remind: Array Ex: int[] number = new int[100]; => fixed-size array declaration Problems: ??? 1 • ArrayLi st Array Lists: offer two significant benefits: Array lists can grow and shrink as needed. The ArrayList class supplies methods for many common tasks, such as inserting and removing elements. 1 • ArrayLi st Syntax: 1 • ArrayLi st Figure 1.1 Adding an Element with add 1 • ArrayLi st Figure 1.2 Adding and Removing Elements in the Middle of an Array List 1 • ArrayLi st SN Methods with Description 1 void add(int index, Object element) Inserts the specified element at the specified position index in this list. 2 boolean add(Object o) Appends the specified element to the end of this list. 3 boolean addAll(int index, Collection c) Inserts all of the elements in the specified collection into this list, starting at the specified position. 4 boolean contains(Object o) Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that (o==null ? e==null : o.equals(e)). 5 Object get(int index) Returns the element at the specified position in this list. 6 Object remove(int index) Removes the element at the specified position in this list. 7 int size() Returns the number of elements in this list. 2 • Linked List A linked list is a data structure used for collecting a sequence of objects that allows efficient addition and removal of elements in the middle of the sequence.