Java record-52-Java Collection class set

Source: Internet
Author: User
Tags sorts

Java record-52-Java Collection class set
The java. util package contains some of the most exciting enhancements added in java 2: class sets. In addition to the class set, java. util also contains various classes and interfaces that support a wide range of functions. Their applications include the generation of pseudo-random numbers, operations on dates and times, observation events, operations on the counterpoint set, and marking strings. Java. util has many features, so it is the most widely used Java package. The following describes in detail the next class set: a collection is a group of objects. The collection framework of Java standardizes the methods that your program uses to process object groups and is designed to contain a set of standard interfaces. Algorithms (Algorithms) are another important part of the class set mechanism. Algorithm operation class set, which is defined as a static method in the Collections class. Each class set class does not have to implement its own solution. The algorithm provides a standard method for processing class sets. The Iterator interface is created by the class set framework. An Iteration Program (iterator) provides a multi-purpose, standardized method for each worker class set of an element. Therefore, the iterator provides an enumerating the contents of a collection method. Because every class set implements Iterator, elements of any class can be accessed through methods defined by Iterator. In addition to the class set, the Framework defines several ing interfaces and classes. Maps stores key/value pairs. Although the ing is not a class set, they are fully integrated with the class set to obtain the ing Class Set "view" (collection-view ), this "View" contains elements from the mappings stored in the class set. Therefore, you can select a ing to process it as a class set class. The class set only provides a better way to handle things. In addition to the class set interface, the class set also uses the Comparator, Iterator, and ListIterator interfaces. The Comparator interface defines how to compare two objects. The Iterator and ListIterator interfaces enumerate objects in the class. The methods provided by the class set interface are optional. The class set that can be modified supports methods that can change the content of the class set. The class set that cannot be modified is not supported. If you use a method to change the content of a class set that cannot be modified, an UnsupportedOperationException is thrown. All built-in class sets can be modified. The Collection interface is the basis for constructing the class set framework. It declares the core methods that all class sets will possess. Because all class sets implement Collection, it is necessary to be familiar with its methods to clearly understand the framework. You can call the add () method to add objects to the class set. Note that add () includes an Object-type parameter. Because objects are superclasses of all classes, any type of objects can be stored in a class set. However, the original type does not work. To store the original type, use the original type package. You can call addAll () to add all content of a class set to another class set. You can delete an object by calling the remove () method. To delete a group of objects, you can call the removeAll () method. You can call the retainAll () method to delete all elements except a group of specified elements. To clear a class set, you can call the clear () method. By calling the contains () method, you can determine whether a class set contains a specified object. To determine whether a class set contains all the elements of another class set, you can call the containsAll () method. When a class set is empty, you can call the isEmpty () method to confirm it. Call the size () method to obtain the number of current elements in the class set. The toArray () method returns an array containing elements stored in the call class set. By providing a set of paths between the class set and array, You can take full advantage of both. Iterator () is a more important method. This method returns an iterator for the class set. Collection: The Root Interface in the Collection hierarchy. JDK does not provide a direct implementation class for this interface. Set: duplicate elements cannot be contained. SortedSet is a Set that sorts elements in ascending order. List: an ordered set that can contain repeated elements. Supports index-based access. Map: contains the key-value pair. Map cannot contain duplicate keys. SortedMap is a Map that sorts keys in ascending order.

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.