JAVA Collection framework (JCF)

Source: Internet
Author: User
Tags java se

JAVA Collection framework (JCF)

Java SE contains a set of classes and interfacesJava Collection frameworkJava Collection Framework (JCF) is used to organize the stored data in a certain structure and access the data in a specific way, the goal is to provide a general framework for processing object sets, which reduces the coding workload when programmers process different object sets, while Java Collection classes are located in java. util package.

Next we will briefly discuss the content of the JCF class. First, the Java Collection framework divides the object storage methods into three types:Set),List),Map).

  Set): The objects in the object container are not ordered and cannot be repeated. The corresponding interface Set; the Set interface inherits all the methods from the Collection interface. For Java beginners, you must first masterHashSet classAndTreeSet class.

  HashSet classThe features are as follows: When HashSet is traversed, the elements in the HashSet are unordered. Repeated elements are not allowed in the HashSet. The repeated elements here refer to the same hash code, when the equals () method is used for comparison, two objects that return true are allowed to contain null elements.

  TreeSet classSort the elements in the natural order of the elements, or sort the elements based on the Comparator provided when the set is created, depending on the construction method used. That is to say, TreeSet supports natural sorting and custom sorting. By default, TreeSet uses the natural sorting method.

  List): Elements in the List are ordered. The List usually allows repeated elements. The List Implementation class usually supports null elements. Elements in the List object container can be accessed through the same index. We need to first understandArrayList classAndThe listlist class.

  ArrayList classSimilar to arrays, ArrayList indicates a group of indexed elements. The difference is that ArrayList has no predefined size and its length can be increased as needed.

  Sort list classIs a list that implements the two-way linked list function. It puts each object in the list in an independent space, and each space also stores the index of the previous and next links; the random list does not support fast random access. To access the nth element in the random list, you must start searching from the beginning and skip the first n-1 element. In addition, although the shortlist also provides a get () method that can obtain corresponding elements based on the specified index, it is inefficient because it does not support fast random access.

  Map): Is another important interface different from the Collection interface in the Java Collection framework. It corresponds to a set of mappings from key to value. That is to say, there are two groups of objects in the Map object container. One group of objects is used to save the key in the Map, and the other group is used to save the value. Key and value can be data of any reference type. The key cannot be repeated, but the value can be repeated. We need to masterHashMap classAndTreeMap class.

  HashMap classIs the implementation of the Map interface based on the hash algorithm. HashMap stores its key in the hash table for maintenance. The key is unique. However, HashMap does not guarantee that keys are arranged in a specific order, especially that the order remains unchanged permanently.

  TreeMap classIs implemented based on the Map interface of the Red-black tree algorithm. The storage mode of the TreeMap key is similar to that of the TreeSet. It stores the keys in the tree. The keys are arranged in natural or custom order.

Related Article

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.