The Interface and Class Hierarchy Diagram of Java Collections

1. Collection vs Collections

First of all, "Collection" and "Collections" are two different concepts. As you will see from the hierarchy diagram below, "Collection" is a root interface in the Collection hierarchy but "Collections" is a class which provide static methods to manipulate on some Collection types.

2. Class hierarchy of Collection

The following diagram demonstrates class hierarchy of Collection.

3. Class hierarchy of Map

Here is class hierarchy of Map.

4. Summary of classes

collection-summary

5. Code Example

The following is a simple example to illustrate some collection types:

List<String> a1 = new ArrayList<String>();
a1.add("Program");
a1.add("Creek");
a1.add("Java");
a1.add("Java");
System.out.println("ArrayList Elements");
System.out.print("\t" + a1 + "\n");
 
List<String> l1 = new LinkedList<String>();
l1.add("Program");
l1.add("Creek");
l1.add("Java");
l1.add("Java");
System.out.println("LinkedList Elements");
System.out.print("\t" + l1 + "\n");
 
Set<String> s1 = new HashSet<String>(); // or new TreeSet() will order the elements;
s1.add("Program");
s1.add("Creek");
s1.add("Java");
s1.add("Java");
s1.add("tutorial");
System.out.println("Set Elements");
System.out.print("\t" + s1 + "\n");
 
Map<String, String> m1 = new HashMap<String, String>(); // or new TreeMap() will order based on keys
m1.put("Windows", "2000");
m1.put("Windows", "XP");
m1.put("Language", "Java");
m1.put("Website", "programcreek.com");
System.out.println("Map Elements");
System.out.print("\t" + m1);

Output:

ArrayList Elements
	[Program, Creek, Java, Java]
LinkedList Elements
	[Program, Creek, Java, Java]
Set Elements
	[tutorial, Creek, Program, Java]
Map Elements
	{Windows=XP, Website=programcreek.com, Language=Java}

Category >> Collections >> Diagram  
If you want someone to read your code, please put the code inside <pre><code> and </code></pre> tags. For example:
<pre><code> 
String foo = "bar";
</code></pre>

  1. sud on 2012-2-3

    it is helpful

  2. Shibi on 2013-9-13

    Excellent illustration. Thanks a lot.

  3. […] 4. 集合类的层次结构 […]

  4. […] 4.  集合类的层次结构 […]

  5. […] The following are the most popular questions of Java collections asked and discussed on Stackoverflow. Before you look at those questions, it’s a good idea to see the class hierarchy diagram. […]

  6. Mdhar on 2013-10-24

    Very good explanation with clear diagrams. Thanks.

  7. 图说Java « 优大网 on 2013-10-29

    […] 4. Collections Class Hierarchy […]

  8. […] 4. 集合类层次结构 注意Collections(工具类) 和 Collection(集合顶层接口) 的区别: 中文参考: Collections […]

  9. […] The interface and class hierarchy diagram for collections with an example program […]

  10. kai ran on 2013-11-25

    Clear explanation, great work!

  11. Bortnikov on 2013-11-29

    You forget
    interface NavigableMap

  12. Li Yang on 2013-12-14

    The graph is very clear~

  13. Ankit Gupta on 2014-2-11

    great explanation… very useful….

  14. Vijay on 2014-3-10

    It is very crisp and clear..

  15. 智 陶 on 2014-3-28

    u missed the abstractinterface,such as abstractcollection,abstractset,abstractlist,Those are important in the hierarchy of java collection.

  16. […] Class hierarchy of Collection and Map […]

  17. […] 4、集合类的层次结构 […]

  18. […] 4.  集合类的层次结构  注意Collections和Collection之间的不同。    […]

  19. […] 4、集合类的层次结构 […]

  20. […] 4、集合类的层次结构 […]

  21. […] 4.  集合类的层次结构 […]

  22. fishnut.ca on 2014-11-5

    fishnut.ca

    The Interface and Class Hierarchy Diagram of Java Collections

  23. […] 4、集合类的层次结构 […]

  24. […] 4、集合类的层次结构 […]

  25. […] 4、集合类的层次结构 […]

  26. […] 4銆闆嗗悎绫荤殑灞傛$粨鏋 […]

  27. […] 4、集合类的层次结构 […]

  28. gowtham Bk on 2016-2-15

    If I wanna add BST to the collection. where should it come?

Leave a comment

*