Java - collection framework and data structure behind it

Keywords: Java data structure linked list list

Objectives of this section

  • Understand what a collection framework is
  • Understand the meaning of learning set framework
  • Master the relevant interfaces and common implementation classes of the collection framework
  • Understand what to learn in the next stage

1. Introduction

Official course
The Java Collection Framework, also known as the container container, is a group defined under the java.util package
Interface interfaces and its implementation classes.

Its main performance is to place multiple elements in a unit for fast and convenient storage, store and retrieval of these elements
retrieve and manage manually, which is commonly known as add, delete, check and modify CRUD.

C: create, insert a record into the database;
R: read, query database records;
U: update to modify database records;
D: Delete to delete the database record.

For example, a deck of playing cards (a set of cards), a mailbox (a set of mail), an address book (a mapping relationship between a set of names and telephones), and so on.
Overview of classes and interfaces

2. Significance of learning

2.1 advantages and functions of Java collection framework

  1. Using a mature collection framework helps us write efficient and stable code conveniently and quickly
  2. Learning the data structure knowledge behind it will help us understand the advantages, disadvantages and usage scenarios of each collection

2.2 written examination and interview questions

tencent-Java Background development experience
1. HashMap Do you understand? Let's introduce it. If an object is key When, hashCode and equals What should we pay attention to in the usage of method?
2. HashSet and HashMap What is the difference?
3. HashMap Is it thread safe? What does thread safety need?
Alibaba-Java Background development experience
1. ArrayList and LinkedList What is the difference?
2. Yes HashMap Is the concrete implementation of?
3. HashMap and ConcurrentHashMap Which is more efficient?
Today's headlines-Java Background development experience
1. Programming problem: judge whether a linked list is a palindrome linked list.
2. Redis of zset Type corresponds to java What is the general type of language?
3. hashCode What is it mainly used for?

3. interfaces

3.1 basic relationship description

  1. Collection: used to store and manage a set of object objects, which are generally called element elements
    1. Set: the element cannot be repeated, which implies the semantics of find / search
      1. SortedSet: an ordered set of non repeatable elements
    2. List: linear structure
    3. Queue: queue
    4. Deque: Dual Ended queue
  2. Map: the key value pair implies search / search semantics
    1. SortedMap: an ordered set of key value pairs

3.2 Collection interface description

Collection official documentation

3.3 description of common methods of collection

3.4 Collection example

import java.util.Collection;
import java.util.ArrayList;
import java.util.Arrays;
public class Demo {
    public static void main(String[] args) {
        Collection<String> list = new ArrayList<>();
        System.out.println(list.size());
        System.out.println(list.isEmpty());
        list.add("I");
        list.add("love");
        list.add("Java");
        System.out.println(list.size());
        System.out.println(list.isEmpty());
        Object[] array = list.toArray();
        System.out.println(Arrays.toString(array));
        for (String s : list) {
            System.out.println(s);
        }
        list.remove("love");
        for (String s : list) {
            System.out.println(s);
        }
        list.clear();
        System.out.println(list.size());
        System.out.println(list.isEmpty());
    }
 }

Operation results:

0
true
3
false
[I, love, Java]
I
 love
Java
 I
Java
0
true

3.5 Map interface description

Map official document

3.6 description of common methods of map

3.7 Map example

import java.util.Map;
import java.util.HashMap;
public class Demo {
  public static void main(String[] args) {
    Map<String, String> map = new HashMap<>();
    System.out.println(map.size());
    System.out.println(map.isEmpty());
    System.out.println(map.get("author"));
    System.out.println(map.getOrDefault("author", "nameless"));
    System.out.println(map.containsKey("author"));
    System.out.println(map.containsValue("nameless"));
    map.put("author", "Lu Xun");
    map.put("title", "A Madman's Diary");
    map.put("Publication time", "1918 year");
    System.out.println(map.size());
    System.out.println(map.isEmpty());
    System.out.println(map.get("author"));
    System.out.println(map.getOrDefault("author", "nameless"));
    System.out.println(map.containsKey("author"));
    System.out.println(map.containsValue("nameless"));
    for (Map.Entry<String, String> entry : map.entrySet()) {
      System.out.println(entry.getKey());
      System.out.println(entry.getValue());
   }
 }
}

Operation results:

0
true
null
 nameless
false
false
3
false
 Lu Xun
 Lu Xun
true
false
 author
 Lu Xun
 Publication time
1918 year
 title
 A Madman's Diary

4. Implement classes


In addition, we will also learn Stack in java

5. Next stage

5.1 objectives

  1. Learn the basic use of the collection framework
  2. Learn basic data structure knowledge
  3. Learn seven comparison based sorting algorithms
  4. Learn relevant java knowledge points

5.2 knowledge points

  1. Use of collection framework

    1. Collection
    2. List
    3. ArrayList
    4. LinkedList
    5. Stack
    6. Queue
    7. PriorityQueue
    8. Deque
    9. Set
    10. HashSet
    11. TreeSet
    12. Map
    13. HashMap
    14. TreeMap
    15. Collections
  2. Theory and implementation of data structure

    1. Sequence table
    2. Linked list
    3. Stack
    4. queue
    5. Binary tree
    6. heap
  3. Sorting algorithm

    1. Insert sort
    2. Shell Sort
    3. Select sort
    4. Heap sort
    5. Bubble sorting
    6. Quick sort
    7. Merge sort
  4. Java syntax

    1. Generic generic
    2. autobox and autounbox
    3. equals method of Object
    4. Comparable and Comparator interfaces

Summary of key contents

The relationship between interfaces and in Java collection framework and its meaning
The relationship between interfaces and their corresponding common implementation classes in the Java collection framework
Main course contents of the next stage

Posted by dig412 on Thu, 25 Nov 2021 22:10:36 -0800