Java. util package (2) -- Connection interface, java. util. locale

Source: Internet
Author: User

Java. util package (2) -- Connection interface, java. util. locale
Connection interface Introduction

The Connection interface is the root interface of the java set and has no implementation class. It only contains sub-interfaces and various containers that implement sub-interfaces. It is mainly used to represent the abstract concept of the java set.

The Connection interface requires that all containers that implement this interface must provide at least two constructor methods: the constructor without parameters and the constructor with parameters of the Connection class. The latter needs to create a new set with the same elements as the parameter to replicate the set. All APIs in java comply with this rule.

If the set does not support certain modification methods, the UnsupportedOperationException must be thrown in the modification method. However, if this modification has no actual effect (for example, adding an empty set to a set), the set may not throw this exception.

For some sets, they have restrictions on the elements they can accommodate. When they try to add, they may throw an unchecked Exception, such as NullPointerException or ClassCastException. During the query, the set may throw an exception or directly return a false value, which indicates a failure, depending on the implementation of the Set.

For comparison of elements in a set, the set may use the equals method or the hashCode method, depending on the implementation of the Set. You cannot simply think that the set will definitely call the equals method. The set may use an appropriate method provided by any Object for element comparison.

In addition, when the set contains its own elements, calling the clone (), hashCode (), equals (), and toString () Methods of the set may fail and an exception is thrown, this leads to recursive calls. Collections can handle such exceptions by themselves, but none of the currently implemented collections are processed.

Methods included in Connection
/*** Method of Determining Class **/int size (); // returns the elements contained in the set. If the value is greater than Integer. MAX_VALUE, returns Integer. MAX_VALUEboolean isEmpty (); // returns trueboolean contains (Object o) if the set is empty; // returns true if the set contains o, classCastException and NullPointerException may be thrown. boolean containsAll (Collection <?> C);/*** conversion class method **/Iterator <E> iterator (); // return the Iterator corresponding to the Set (this is because Connection inherits the Iterable Interface) object [] toArray (); // converts a set to an array <T> T [] toArray (T [] a); // converts a set to an array, and keep the input type/*** operation method **/boolean add (E e); boolean addAll (Collection <? Extends E> c); boolean remove (Object o); boolean removeAll (Collection <?> C); boolean removeIf (Predicate <? Super E> filter); // by default, this method implements boolean retainAll (Collection <?> C); // only retain the void clear () element in the parameter ();

 

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.