Collection and collections

Source: Internet
Author: User

CollectionYesJavaThe interface under. util, which is the parent interface of various collection structures.

CollectionsYesJavaClass under. util, which contains various static methods related to set operations.

CollectionThe Root Interface in the hierarchy.CollectionRepresents a group of objects, also known
CollectionOfElement. Some
CollectionRepeated elements are allowed, while others are not. Some
CollectionIs ordered, while others are disordered. JDK does not provide anyDirectImplementation: it provides more specific sub-interfaces (such as set and list) implementation. This interface is usually used to pass
CollectionAnd operate on these
Collection.

Collection
Shortlist
│ Invalid parameter list
│ ├ Arraylist
│ Vector
│ Elastic Stack
Sorted set

CollectionsThis class is entirely caused
CollectionOr return
CollectionStatic method. It is included in
CollectionThe multi-state algorithm operated on, that is, the package.
CollectionSupported new
Collection
And a few others. If
Collection
Or if the class object is null, these methods will throw nullpointerexception.

 JavaCode

  1. Import Java. Util. arraylist;
  2. Import Java. Util.Collections;
  3. Import Java. Util. List;
  4. Public ClassTestcollections {
  5. Public Static VoidMain (string ARGs []) {
  6. // Note that list is an implementationCollectionInterface
  7. List list =NewArraylist ();
  8. DoubleArray [] = {112,111, 23,456,231 };
  9. For(IntI = 0; I <array. length; I ++ ){
  10. List. Add (NewDouble (array [I]);
  11. }
  12. Collections. Sort (list );
  13. For(IntI = 0; I <array. length; I ++ ){
  14. System. Out. println (list. Get (I ));
  15. }
  16. // Result: 23.0 111.0 112.0 231.0 456.0
  17. }
  18. }
  19. Collection: The upper-level interface of the Collection class. The interfaces inherited from it mainly include set and list.

    Collections: PairCollectionThe Collection class of some static methods of object operations, such as sorting, thread synchronization, and search, is actually a helper class. The return type of these methods is basicallyCollectionAnd a few others.

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.