Summary of the Java Collection framework

Source: Internet
Author: User
Tags set set

Essay Classification-Javajava Collection Framework Summary (5)--map Interface Usage Summary: Map is used to save the data (Key-vlaue) with the mapping relationship. The key of map does not allow repetition, that is, any two key of the same map object is always returned by the Equals method. The Falsemap contains a keyset () method that returns the set set of the map so that key is composed. The map collection is similar to the storage of set elements, such as HashSet, Linkedhashset, SortedSet (interface), TreeSet, Enumset, and so on, while the map interface has HashMap, Linkedhashmap, SortedMap (interface), TreeMap, Enummap, and other implementation classes and sub-interfaces. The value of map is very similar to list: element Read full text Java Collection framework summary (4)--list Interface Usage Summary: The list collection represents an ordered set, and each element in the collection has its corresponding sequential index. The list collection allows you to use duplicate elements, which can be indexed to access the collection elements at the specified location. 1, List interface and Listiterator interface list as a sub-interface of the collection interface, you can use all the methods in the collection interface. The list is an ordered set, so the list collection adds some methods to manipulate the collection elements according to the index: void Add (int index, Object Element): Inserts element elements at index of the list collection. Boolean addall (int index, Collection c): Inserts all the elements contained in collection C into the list. Read the full text of the Java Collection Framework Summary (3) Summary of sorting issues for the--treeset class: TreeSet supports two sorts of sorting methods: natural sorting and custom sorting. TreeSet is naturally sorted by default. 1. Natural sort TreeSet invokes the CompareTo (Object obj) method of the collection element to compare the size relationship between elements, and then arranges the collection elements in ascending order, which is a natural sort. (The premise of comparison: two objects of the same type). Java provides a comparable interface that defines a CompareTo (object obj) method that returns an integer value that the class implementing the interface must implement, and the object of the class that implements the interface can compare size. When an object calls the method to compare with another object, such as Obj1.comparto (OBJ2), if the method returns 0,It indicates that both read the full text of the Java Collection Framework summary (2) The usage summary of the--set interface: 1. There is no obvious order between multiple objects in the set set of the set interface. For details, refer to the API documentation (see how important it is to bring the API documentation with you at any time), essentially the same as the collection method. Just behave differently (set does not allow repeating elements). The set collection does not allow repeating elements, because set determines that two objects are the same not using the = = operator, but rather by the Equals method. That is, two objects cannot accept two objects by using the Equals method to return a true,set. public class testset{public static void Main (string[] args) {set<string> books = new Hashset<stri read the knowledge of the full-text Java collection framework General Summary (1) Summary: Description: First introduced the Java Collection framework contains the interface and classes, and then summed up the collection framework of some basic knowledge and key points, and combined with examples for a simple analysis. 1. Summary All collection classes are located under the Java.util package. Only objects can be saved in the collection (a reference variable that holds the object). (Arrays can hold both basic types of data and objects). When we put an object into the collection, the system treats all the collection elements as instances of the object class. Since JDK1.5, this state has improved: You can use generics to constrain the type of elements in a collection and let the collection remember the type of all the elements of the collection (see specific generic content). The Java collection class is mainly derived from two interfaces: Collection and map,collection and map are the root of the Java Collection Framework read the full textCopy to Google TranslateTranslation Results

Summary of the Java Collection framework

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.