O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.
Collections FrameWork
ArrayDqueue
Sorting & Reverse Techniques
Collections Framework
• The Java Collections Framework is a collection of interfaces and classes
which helps in storing an...
List
• A List is an ordered Collection (sometimes called a sequence)
• Lists may contain duplicate elements.
• Elements ca...
ArrayList
• ArrayList is a resizable-array implementation of the List interface.
• It implements all optional list operati...
LinkedList
• LinkedList is a doubly-linked list implementation of
the List and Deque interfaces
• The LinkedList class ext...
Difference between ArrayList and
LinkedList
• Since Array is an index based data-structure searching or getting element
fr...
Set Interface
• A Set is a Collection that cannot contain
duplicate elements
• .There are three main implementations of Se...
HashSet
• HashSet extends AbstractSet and implements the Set interface.
• It creates a collection that uses a hash table f...
Tree Set Class
• TreeSet is similar to HashSet except that it
sorts the elements in the ascending order
• TreeSet does not...
LinkedHashSet
• LinkedHashSet is also an implementation of
Set interface
• LinkedHashSet maintains the insertion order.
El...
ArrayDeque Class
• java.util.ArrayDeque implements a double-ended queue, which allows
efficient insertion and deletion at ...
Sorting
import java.util.ArrayList;
import java.util.Collections;
public class Sorting_Array_List {
public static void mai...
Reverse
import java.util.ArrayList;
import java.util.Collections;
public class Reverse_ArrayList {
public static void main...
Próximos SlideShares
Carregando em…5
×

Collections framework in java

320 visualizações

Publicada em

Collection in java,ArrayDeque,Sorting,Reverse order

Publicada em: Educação
  • Seja o primeiro a comentar

Collections framework in java

  1. 1. Collections FrameWork ArrayDqueue Sorting & Reverse Techniques
  2. 2. Collections Framework • The Java Collections Framework is a collection of interfaces and classes which helps in storing and processing the data efficiently • This framework has several useful classes which have tons of useful functions which makes a programmer task super easy.
  3. 3. List • A List is an ordered Collection (sometimes called a sequence) • Lists may contain duplicate elements. • Elements can be inserted or accessed by their position in the list, using a zero-based index.
  4. 4. ArrayList • ArrayList is a resizable-array implementation of the List interface. • It implements all optional list operations, and permits all elements, including null. • this class provides methods to manipulate the size of the array that is used internally to store the list • Example program for ArrayList
  5. 5. LinkedList • LinkedList is a doubly-linked list implementation of the List and Deque interfaces • The LinkedList class extends AbstractSequentialList and implements the List interface • It provides a linked-list data structure. • Example of LinkedList
  6. 6. Difference between ArrayList and LinkedList • Since Array is an index based data-structure searching or getting element from Array with index is pretty fast. Array provides O(1) performance for get(index) method but remove is costly in ArrayList as you need to rearrange all elements. On the Other hand LinkedList doesn't provide Random or index based access and you need to iterate over linked list to retrieve any element which is of order O(n). • LinkedList has more memory overhead than ArrayList because in ArrayList each index only holds actual object (data) but in case of LinkedList each node holds both data and address of next and previous node.
  7. 7. Set Interface • A Set is a Collection that cannot contain duplicate elements • .There are three main implementations of Set interface: HashSet, TreeSet, LinkedHashSet
  8. 8. HashSet • HashSet extends AbstractSet and implements the Set interface. • It creates a collection that uses a hash table for storage. • A hash table stores information by using a mechanism called hashing. • In hashing, the informational content of a key is used to determine a unique value, called its hash code. • The hash code is then used as the index at which the data associated with the key is stored • Keypoints of HashSet • HashSet doesn’t maintain any order • HashSet doesn’t allow duplicates • HashSet allows null values however if you insert more than one nulls it would still return only one null value • Example Program
  9. 9. Tree Set Class • TreeSet is similar to HashSet except that it sorts the elements in the ascending order • TreeSet does not allows null element • Example Program
  10. 10. LinkedHashSet • LinkedHashSet is also an implementation of Set interface • LinkedHashSet maintains the insertion order. Elements gets sorted in the same sequence in which they have been added to the Set. • Example program
  11. 11. ArrayDeque Class • java.util.ArrayDeque implements a double-ended queue, which allows efficient insertion and deletion at both ends. • ArrayDeque is a resizable array implementation of the Deque interface • It will perform faster than stack when used as stack and faster than linked list when used access by multiple threads • Null elements are prohibited. • Example program
  12. 12. Sorting import java.util.ArrayList; import java.util.Collections; public class Sorting_Array_List { public static void main(String[] args) { ArrayList<Integer> Integer_sort=new ArrayList<Integer>(); In`teger_sort.add(1); Integer_sort.add(0); Integer_sort.add(8); Integer_sort.add(3); //the output will show unsorted integers System.out.println("Before sorting"+Integer_sort); //now sorting the integers Collections.sort(Integer_sort); System.out.println("After sorting"+Integer_sort); //we can access this collection with iterator also } } ####output#### Before sorting[1, 0, 8, 3] After sorting[0, 1, 3, 8]
  13. 13. Reverse import java.util.ArrayList; import java.util.Collections; public class Reverse_ArrayList { public static void main(String[] args) { ArrayList<Integer> Integer_sort=new ArrayList<Integer>(); Integer_sort.add(1); Integer_sort.add(2); Integer_sort.add(3); Integer_sort.add(4); //the output will show sorted integers System.out.println("Before reverse"+Integer_sort); //now reverse the integers Collections.reverse(Integer_sort); System.out.println("After sorting"+Integer_sort); //we can access this collection with iterator also } } ####output#### Before reverse[1, 2, 3, 4] After sorting[4, 3, 2, 1]

×