Core java - Advance Topics
  • Welcome
  • Schedule
  • 1) Exception Handling
    • 1) Introduction to Exception Handling
    • 2) Categories of Exceptions
    • 3) Creating a method that throws an exception
    • 4) Creating Custom Exception Classes
    • 5)What happens when an exception is thrown?
      • 5.1) Creating try-catch-finally blocks
      • 5.2) Using a method that throws a checked exception
      • 5.3) Using a method that throws a runtime exception
      • 5.4) Using a method that throws an error
      • 5.5) Will a finally block execute even if the catch block defines a return statement?
      • 5.6) What happens if both a catch and a finally block define return statement?
      • 5.7) What happens if a finally block modifies the value returned from a catch block?
      • 5.8) Can a try block be followed only by a finally block?
      • 5.9) Does the order of the exceptions caught in the catch blocks matter?
      • 5.10) Can I rethrow an exception or the error I catch?
      • 5.11) Can I declare my methods to throw a checked exception instead of handling it?
      • 5.12) I can create nested loops, so can I create nested try-catch blocks too?
      • 5.13) Should I handle errors?
    • 6) Best Practices
    • 7) Cheat Sheet
    • 8) Problems
  • 2) Wrapper Classes and Enums
    • 2.1) Creating objects of the wrapper classes
    • Enums
  • 3) Inner Classes
    • 3.1) Static nested class (also called static inner class)
    • 3.2) Inner class (also called member class)
    • 3.3) Anonymous inner class
    • 3.4) Method local inner classes
    • CheatSheet
  • 4) Generics
    • Multiple Type parameters in Generic classes
    • Inheritance using Generics
    • Generic interfaces
    • Generic Methods
    • Bounded type parameters
    • Applications
  • 5) Equals and Hashcode
    • Problems
  • CompareTo method overview
  • Basic DS
    • 1) Simple Array List
    • 2) Simple HashMap
  • 5) Collections Framework - Part 1
    • Introducing the collections framework
    • Working with the Collection interface
      • The core Collection interface
      • Methods of the Collection interface
    • Creating and using List, Set, and Deque implementations
      • List interface and its implementations
      • Iterators
      • Sorting List using custom sorting technique
      • Comparable Interface
      • Custom Sorting using comparator
      • ArrayList - Examples and practice problems
    • Stack
    • Linked List
    • LinkedList Operations
  • 6) Collections Framework - Part 2
    • Sets
      • Set Types
      • Array to Set (vice versa)
    • Maps
    • TreeMap
    • Autoboxing And Unboxing
  • Collections Framework - Part 3
    • Basics : DS , Number System
    • Internal Working
      • HashMap
      • HashSet
  • 7) Reflection API
  • 8) Annotations
  • 9) Reading Input From Various Sources
    • File Handling
    • Reading From Xml
    • Reading From JSON
  • 10) Multi-threading (Concurrency)
    • Protect shared data
    • Thread-safe access to shared data
  • 11) Design Patterns
    • Singleton
    • DI
  • 12) Internal Working of JVM
  • 13) Garbage Collection
  • 14) More on Strings (Buffer and Builder)
  • 15) Cloning and Immutable Class
    • 16) Serialization And Deserialization
    • Untitled
  • JAVA 8
    • Interface Changes
    • Lambda
    • Method Ref
    • Optional
    • Streams
    • Predicates
  • Practice Tests
    • Test - Collections
    • OOPS
    • S-OOPS
Powered by GitBook
On this page

Was this helpful?

  1. 5) Collections Framework - Part 1

Introducing the collections framework

Previous5) Collections Framework - Part 1NextWorking with the Collection interface

Last updated 5 years ago

Was this helpful?

Imagine that you have to process a list of results submitted by registered users of your website for an opinion poll. You aren’t concerned about the order of receiving or processing these results, but you won’t accept multiple votes from the same user. Imagine that in another case, you’re creating a drawing application that includes an Undo button. You need to keep track of the order in which the drawing commands are selected, so you can undo the last command. Duplicate commands are allowed in a drawing application. Imagine yet another case, when you’re looking up a word in a dictionary. The words are ordered alphabetically, but duplicate words don’t exist in the dictionary.

These scenarios show examples of needing to store and retrieve collections of data in various manners. For one collection, you might need to retrieve data in the order in which it was generated. For another collection, you might not allow duplicate values but would prefer data to be sorted on a data item.

A collection is an object that can group other objects. Each object in a collection is referred to as an element. The Java collections framework is architecture for represent- ing and manipulating collections. This framework defines many interfaces to support the need for storing a collection of data in various formats. These collections might need to be ordered, to be sorted, to allow duplicate values, to be immutable, to be of fixed size, and more. The collections framework includes high-performance, high- quality implementations of useful data structures to store a collection of your objects. It includes the following:

  • Interfaces—Multiple interfaces like List, Set, Deque, and Map model the data structures used for storing, accessing, and manipulating a collection of data.

  • Implementations —Concrete classes like ArrayList, HashSet, and TreeMap imple-

    ment the interfaces.

  • Algorithms—Classes like Collections and Arrays contain utility methods like

    sort() and search() for sorting and searching List objects or arrays.

Don’t confuse the interface Collection with the class Collections. Collection is the base interface in the collections framework that is extended by most of the other interfaces. Class Collections defines utility methods to operate on or return collections.

But at the same time, using the collections framework can be overwhelming. The key to optimal use of the collections framework is to get the basics right. So, let’s start with the base interface in the Java collections framework: Collection.

Collections Framework :

Depending on how you need to process a collection of data, you might need a data structure that can sort the collection values, retain the insertion order of the elements, and not allow duplicate elements.
The main interfaces and their implementations in the collections framework. Class Collections, a utility class that implements various algorithms for searching and sorting, is also a part of the collections framework.