Java Collection Framework (JCF)

Source: Internet
Author: User
Tags java se

Java SE contains a Java collection framework consisting of a set of classes and interfaces (the Java Collection Framework, referred to as JCF), whose primary function is to organize the stored data in a certain structure and access that data in a specific way. The goal is to provide a common framework for working with collections of objects, reducing the amount of code that programmers use when dealing with different sets of objects, while Java collection classes are located in the Java.util package.

Next, we will briefly talk about the contents of the JCF class. The Java Collection framework first divides the storage of objects into three types:set (set),list,map (map).

  set: Objects in the object container do not have order, and can not be repeated, the corresponding interface Set;set interface inherits from the collection interface all methods, for us Java beginners, we need to first grasp the Set interface under the HashSet class and the TreeSet class .

  HashSet class is characterized by: when traversing hashset, the elements of which are not sequential, the hashset is not allowed to duplicate elements, where the repeating elements are the same hash code, and the Equals () method for comparison, Two objects that return true; allow the inclusion of a null element.

  Depending on the construction method used, the TreeSet class uses the natural order of the elements to sort the elements, or to sort the comparator that are provided when the set is created. In other words, TreeSet supports both natural and custom sorting methods. By default, the TreeSet is in a natural sort mode.

  list: The elements in the list are sequential; The list usually allows repeating elements; The list's implementation class usually supports NULL elements; You can access the elements in the List object container with the same index. We need to first master the ArrayList class and the LinkedList class under that interface.

The ArrayList class is conceptually and array-like, representing a set of indexed elements, the difference being that the ArrayList has no predetermined size, and its length can be increased as needed.   

  The LinkedList class is a list of two-way linked lists, which places each object in the list in a separate space, and each space holds an index of the previous and next links; LinkedList does not support fast random access. If you want to access the nth element in LinkedList, you must find it from the beginning, and then skip the previous n-1 elements. And, although LinkedList also provides a get () method that can fetch the corresponding element based on the specified index, it is inefficient because it does not support fast random access.

  Map: is another important interface in the Java Collection framework that differs from the collection interface, which corresponds to a collection of correspondence between a key (key) and a value (value). That is, the map type Object container holds two sets of objects, one set of objects to hold the key in the map, and the other to hold the value. Key and value can be data of any reference type. Key cannot be duplicated, but value can be repeated. We need to master the HashMap class and the TreeMap class first.

  The HashMap class is the implementation of the map interface based on the hash algorithm. HashMap stores its keys in a hash table for maintenance, and the keys are unique. However, HashMap does not guarantee that the keys are arranged in a particular order, especially if the order is permanent.

  The TreeMap class is a map interface implementation based on the red-black tree algorithm. The TreeMap Middle key is stored in the same way as the TreeSet, which stores the key in the tree, and the order of the keys is arranged in either natural order or custom order.

Java Collection Framework (JCF)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.