• The Interface and Class Hierarchy Diagram of Java Collections


    原文链接:http://www.programcreek.com/2009/02/the-interface-and-class-hierarchy-for-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("	" + a1 + "
    ");   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("	" + l1 + "
    ");   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("	" + s1 + "
    ");   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("	" + 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}
  • 相关阅读:
    FZU 2113 BCD Code 数位dp
    Gym 100917L Liesbeth and the String 规律&&胡搞
    Gym 100917C Constant Ratio 数论+暴力
    CF149D Coloring Brackets
    P4342 [IOI1998]Polygon
    P4316 绿豆蛙的归宿
    P1439 【模板】最长公共子序列
    Noip 2013 真题练习
    洛谷比赛 「EZEC」 Round 4
    P5024 保卫王国
  • 原文地址:https://www.cnblogs.com/ZBug/p/4585758.html
Copyright © 2020-2023  润新知