Jdk_api Anatomy of the Java.util pack

Source: Internet
Author: User
Tags event listener

Java Utility Class Library Java.util package. In this package, Java provides some useful methods and data structures.

First, interface 1, collection<e>
    • Interface
    • Starting from 1.2 There are
    • Inherit iterable<e>
    • The root interface in the Collection hierarchy . Collection represents a set of objects, also known as Collection elements . Some collection allow duplicate elements, while others do not. Some of the collection are orderly, while others are unordered. The JDK does not provide any direct implementation of this interface: it provides more specific sub-interfaces (such as Set and List) implementations. This interface is often used to pass collection and operate these collection where it is required to be the most universal.
2, comparator<t>
    • Interface
    • Starting from 1.2 There are
    • No parent class
    • A comparison function that forces the overall ordering of an object collection. You can pass Comparator to the sort method, such as Collections.sort or Arrays.sort , allowing for precise control over the sort order. You can also use Comparator to control the order of certain data structures, such as 有序 set or 有序映射 , or to provide sorting for objects that are not 自然顺序 collection.
3, deque<e>
    • Interface
    • Starting from 1.6 There are
    • Inherit queue<e>
    • A linear collection that supports inserting and removing elements at both ends. The name deque is the abbreviation for double ended queue (double-ended queues), which is usually read as "deck". Most Deque implementations have no fixed limit on the number of elements they can contain, but this interface supports both a capacity-constrained double-ended queue and a double-ended queue without a fixed size limit.

4, Enumeration<e>
    • Interface
    • Starting from 1.0 there are
    • Inherit queue<e>
    • An object that implements the enumeration interface, which generates a series of elements, one at a time. A sequential call nextElement method returns a series of contiguous elements.

      For example, to output all elements of vector<e> v , you can use the following methods:

         for (enumeration<e> E = v.elements (); e.hasmoreelements ();)       System.out.println (e.nextelement ());

      These methods are enumerated primarily through the elements of the vector, the keys of the Hashtable, and the values in the hash table. The enumeration is also used to specify the input stream SequenceInputStream in.

      Note: The functionality of this interface is duplicated with the functionality of the Iterator interface. Additionally, the Iterator interface adds an optional remove operation and uses a shorter method name. The new implementation should prioritize the use of the Iterator interface instead of the enumeration interface.

5. EventListener
    • Tag interface
    • Starting from 1.1 There are
    • No parent
    • All event listener interfaces must be extended by the markup interface.

    • No method definition
6. formattable
    • Interface
    • Starting from 1.5 There are
    • No parent
    • The formattable interface must be implemented by any class that needs to perform a custom format (using Formatter the ' s ' conversion specifier). This interface allows basic control over the formatting of arbitrary objects.

7, Iterator<e>
    • Interface
    • Starting from 1.2 There are
    • No parent
    • An iterator that iterates over the collection. Iterators replace the enumeration in the Java collections Framework. Iterators are two points different from enumerations:

      • Iterators allow callers to take advantage of well-defined semantics to remove elements from the collection that iterators point to during iterations.
      • The method name has been improved.

      This interface is a member of the Java collections Framework.

8, List<e>
  • Interface
  • Starting from 1.2 There are
  • Inherit collection<e>
  • An ordered collection (also known as a sequence ). Users of this interface can precisely control the insertion position of each element in the list. The user can access the element based on the integer index of the element (where it is located in the list) and search for the elements in the list.

    Unlike set, a list usually allows repeating elements. More specifically, lists generally allow for e1.equals (E2) elements to E1 and E2, and if the list itself allows null elements, they usually allow multiple null elements. It's hard to avoid repeating lists by throwing a run-time exception when a user tries to insert a repeating element, but we hope that the less you can use it, the better.

    List interface in iterator,add,remove,equals , and hashcode The contract for the method is added with some additional conventions that exceed the conventions specified in the Collection interface. For convenience, the declarations for other inherited methods are also included here.

    The list interface provides 4 ways to locate (index) a list element. The list (like a Java array) is based on 0. Note that these operations may be performed in a time proportional to the index values of some implementations, such as the LinkedList class. Therefore, if the caller does not know the implementation, then iterating over the list element is usually better than iterating through the list with an index.

    The List interface provides a special iterator, called Listiterator, that allows element insertion and substitution, as well as bidirectional access, in addition to the normal operation that the Iterator interface provides. It also provides a way to get a list iterator starting at the specified position in the list.

    The List interface provides two ways to search for a specified object. From a performance standpoint, these methods should be used with care. In many implementations, they perform a high-overhead linear search.

    The list interface provides two ways to efficiently insert and remove multiple elements at any point in the list.

    Note: Although the list allows itself to be included as an element, it is recommended to be particularly cautious: on such lists, theequals and hashcode methods are no longer well-defined.

    Some list implementations have restrictions on the elements that a list may contain. For example, some implementations prohibit null elements, while some implementations have restrictions on the types of elements. Attempting to add an unqualified element throws an unchecked exception, usually nullpointerexception or classcastexception. Attempts to query for the presence of unqualified elements may throw an exception, or it may simply return false; Some implementations take the previous behavior, while others use the latter. In a nutshell, when trying to perform an action on an unqualified element, if the operation does not result in an unqualified element being inserted into the list, the operation may throw an exception or succeed, depending on the choice of implementation. The specification for this interface marks such exceptions as "optional."

    This interface is a member of the Java collections Framework.

9, Listiterator<e>
    • Interface
    • Starting from 1.2 There are
    • Inherit iterator<e>
    • Series Table iterators, which allow programmers to traverse the list in either direction, modify the list during iteration, and get the current position of the iterator in the list. The listiterator has no current element, and its cursor position is always located between the element returned by the call to previous () and the element returned by the call next () . An iterator with a list of length n has n+1 a possible pointer position, as illustrated by the following caret:

                            Element (0)   Element (1)   element (2)   ... Element (n-1) cursor positions: ^ ^ ^ ^ ^                  

      Note that the remove() and set(Object) methods are not defined according to the cursor position; they are defined according to the operation of the next() previous() last element that is called or returned.

10, map<k,v>
    • Interface
    • Starting from 1.2 There are
    • No parent
    • The object that maps the key to a value. A map cannot contain duplicate keys, and each key can be mapped to at most one value.

      This interface supersedes the Dictionary class, which is entirely an abstract class, not an interface.

      The map interface provides three collection views that allow you to view the contents of a map in the form of a keyset, value set, or key-value mapping relationship set. The mapping order is defined as the order in which iterators return their elements on the mapped collection view. Some mapping implementations can explicitly guarantee their order, such as the TreeMap class, while others do not guarantee the order, such as the HashMap class.

11, Map.entry<k,v>
    • Interface
    • Starting from 1.2 There are
    • Inherit iterator<e>
    • Mapping entries (key-value pairs). The Map.entryset method returns the collection view of the map, where the elements belong to this class. The only way to get a mapping item reference is through an iterator to this collection view. These map.entry objects are valid only during iterations, or, more specifically, if the underlying mappings are modified after an iterator returns an item, the behavior of some of the mappings is indeterminate, except through setValue Perform actions on the map item.

Jdk_api Anatomy of the Java.util pack

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.