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: