Hierarchical relationship between java Collection interface and Collections Class, Class Diagram

Source: Internet
Author: User

Hierarchical relationship between java Collection interface and Collections Class, Class Diagram

First, let's take a look at the difference between Collection and Collections. Collection and Collections are two completely different concepts. Collections is a java. util class that contains various static methods related to set operations. Collection is an interface under java. util. It is the parent interface of various Collection structures.

Diagram of Collections in java:

Collection is an interface for various sets. Let's take a look at the following hierarchy:

There is also a map hierarchy:

Sample Code:

 

Package com. zz. chain; import java. util. arrayList; import java. util. hashMap; import java. util. hashSet; import java. util. using list; import java. util. list; import java. util. map; import java. util. set;/*** sample code * Copyright May 31, 2015 * created by txxs * all right reserved */public class Test {public static void main (String [] args) {List
 
  
A1 = new ArrayList
  
   
(); A1.add (Program); a1.add (Creek); a1.add (Java); a1.add (Java); System. out. print (ArrayList Elements :); System. out. print (a1 +); List
   
    
L1 = new shortlist
    
     
(); L1.add (Program); l1.add (Creek); l1.add (Java); l1.add (Java); System. out. print (shortlist Elements :); System. out. print (l1 +); Set
     
      
S1 = new HashSet
      
        (); // Or new TreeSet () will order the elements; s1.add (Program); s1.add (Creek); s1.add (Java); s1.add (Java); s1.add (tutorial ); system. out. print (Set Elements :); System. out. print (s1 +); Map
       
         M1 = new HashMap
        
          (); // Or new TreeMap () will order based on keysm1.put (Windows, 2000); m1.put (Windows, XP); m1.put (Language, Java); m1.put (Website, programcreek.com); System. out. print (Map Elements :); System. out. print (m1 );}}
        
       
      
     
    
   
  
 

Running result:

 

 

 

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.