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

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}
时间: 2024-10-05 13:52:06

The Interface and Class Hierarchy Diagram of Java Collections的相关文章

What’s the difference between an interface and an abstract class in Java?

原文 What’s the difference between an interface and an abstract class in Java? It’s best to start answering this question with a brief definition of abstract classes and interfaces and then explore the differences between the two. A class must be decla

Java Collections Framework 汇总

1. Java Collections Framework Java集合框架概览 2. Java Collections Framework 之 RandomAccess接口 3. 关于ArrayList.clear()与=null以及new ArrayList<E>()

关于Java Collections API您不知道的5件事,第2部分

注意可变对象 java.util 中的 Collections 类旨在通过取代数组提高 Java 性能.如您在 第 1 部分 中了解到的,它们也是多变的,能够以各种方 式定制和扩展,帮助实现优质.简洁的代码. Collections 非常强大,但是很多变:使用它们要小心,滥用它们会带来风险. 1. List 不同于数组 Java 开发人员常常错误地认为 ArrayList 就是 Java 数组的替代品.Collections 由数组支持,在集合内随机查找内容时性能较好. 与数组一样,集合使用整序

【DataStructure】The description of Java Collections Framework

The Java Connections FrameWork is a group of class or method and interfacs in the java.util package. Its main purpose is to provide a unified framework for implementing common data structure. A collections is a object that contains other objects,whic

Java数据结构之Java Collections API中的表

1.Collection接口 位于java.util包中,以下是重要的部分. 1 public interface Collection<AnyType> extends Iterable<AnyType> 2 { 3 int size(); 4 boolean isEmpty(); 5 void clear(); 6 boolean add(AnyType x); 7 boolean remove(AnyType x); 8 java.util.Iterator<AnyTy

Java Collections的排序之二

package test.list; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Set; import java.util.TreeSet; public class Link_T

Java Collections.sort方法对list集合排序

1.排序测试类 package com.ljq.test; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; public class UserSort { public static void main(String[] args) { List<User> userList =new ArrayList<User&g

Java Collections 与 Arrays

java 集合类提供了一套设计良好的对一组对象进行操作的类和接口,其中最基本的有以下4个接口 1.Collection.  接口,代表一组对象 2.set.  继承Collection<E>,代表一组不重复的对象 3.List . 继承自Collection<E> ,有顺序的一组对象,可以重复. 4.Map.  接口,直接继承自Object ,通过唯一的key对应value. 为了方便对集合或者数组的操作,集合工具类中提供了Collections  和  Arrays  类分别对集

java Collections.sort()实现List排序自定义方法

方法一: package testSimple; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; public class testCollectionSort { public static void main(String[] args) { List<TblPowerGroup> list = new ArrayLis