Java Collection Learning (ii)

Source: Internet
Author: User

Collection Implementation class:
1. Public abstract class abstractcollection<E> extends Object implements Collection<e>:
The basic framework of the collection class is implemented to reduce the workload of implementing the collection interface.
In order to implement an interface that cannot be modified, you need to inherit the class and implement the iterator and size methods of the interface. The iterator method returns a class iterator that must implement the Hasnext and next methods.
To implement a modifiable interface, you need to override the Add method of the class, or you will throw a unsupportedoperationexception exception. The returned iterator class iterator must implement the Remove method.
As the collection interface recommends, this class typically implements two constructors, one is the void parameter and the other is the collection entry.
Main methods:
Public abstract iterator<e> Iterator(): Returns an iterator that points to the collection element;
P
ublic string toString(): Returns the string description of the current collection;

2.
public abstract class abstractlist <E> extends abstractcollection <E> implements List <e>:
The class implements the list interface basic framework, Mainly for random access data storage methods, such as arrays. Data that is accessed sequentially for similar linked lists is more inclined to use   the abstractsequentiallist class.
in order to implement a list that cannot be modified, simply inherit the class and provide get (int), the size () method implementation.
in order to implement a list that can be modified, you need to override the set (int, E) method Extra, otherwise the unsupportedoperationexception exception will be thrown. If the list is variable-length, an additional rewrite of the Add (int, E) and remove (int) methods is required.
Also, as recommended by the collection interface, you typically need to provide a void constructor and a collection constructor.
Unlike other abstract interfaces, this class does not need to implement iterators. Iterators and List iterators are implemented in the following random access functions: Get (int)
, set (int e),  add (int e)  and  Remove (int) .

This class is java One of the collections Framework members.

3.
public abstract class abstractqueue <e> extends abstractcollection <e>implements Queue <e>:
This class provides a basic implementation of the queue operation. For a method implementation that does not allow empty elements in a base class, the class is handled appropriately. The method Add,move,element is based on Offer,poll,peak, which usually throws an exception instead of a hint failure or returns NULL.
When the queue inherits the class, you need to implement at least Queue.offer (E) methods that do not allow the insertion of empty elements, and Queue.peek (), Queue.pool (), queue.size (), Support Iterator.remove () The Collection.iterator () method. Alternatively, the method can optionally be overridden. If the above conditions are not met, you may consider selecting other subclasses of Abstractcollection.

This class is one of the Java Collection Framework members.



Java Collection Learning (ii)

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.