Java中的集合和集合之间的主要区别是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1796275/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 22:44:51  来源:igfitidea点击:

What is the main difference between Collection and Collections in Java?

javacollections

提问by Nirmal

What is the main difference between Collection and Collections in Java?

Java中的集合和集合之间的主要区别是什么?

采纳答案by Mirek Pluta

Collectionis a base interface for most collection classes, whereas Collectionsis a utility class. I recommend you read the documentation.

Collection是大多数集合类的基本接口,而Collections是实用程序类。我建议您阅读文档。

回答by uckelman

Are you asking about the Collectionsclass versus the classes which implement the Collectioninterface?

您是在询问Collections类还是实现Collection接口的类?

If so, the Collections class is a utility class having static methods for doing operations on objects of classes which implement the Collection interface. For example, Collections has methods for finding the max element in a Collection.

如果是这样,Collections 类是一个实用程序类,具有对实现 Collection 接口的类的对象进行操作的静态方法。例如,Collections 具有用于查找 Collection 中最大元素的方法。

The Collection interface defines methods common to structures which hold other objects. List and Set are subinterfaces of Collection, and ArrayList and HashSet are examples of concrete collections.

Collection 接口定义了保存其他对象的结构的通用方法。List 和 Set 是 Collection 的子接口,ArrayList 和 HashSet 是具体集合的示例。

回答by Esko

Collection, as its javadoc says is "The root interface in the collection hierarchy." This means that every single class implementing Collectionin any form is part of the Java Collections Framework.

Collection,正如它的 javadoc 所说的是“集合层次结构中的根接口这意味着Collection以任何形式实现的每个类都是Java 集合框架的一部分

The Collections Framework is Java's native implementation of data structure classes (with implementation specific properties) which represent a group of objects which are somehow related to each other and thus can be called a collection.

集合框架是 Java 对数据结构类(具有特定于实现的属性)的本地实现,这些类表示一组以某种方式相互关联的对象,因此可以称为集合。

Collectionsis merely an utility method class for doing certain operations, for example adding thread safety to your ArrayListinstance by doing this:

Collections只是用于执行某些操作的实用程序方法类,例如通过执行以下操作为您的ArrayList实例添加线程安全性:

List<MyObj> list = Collections.synchronizedList(new Arraylist<MyObj>());

The main difference in my opinion is that Collectionis base interface which you may use in your code as a type for object (although I wouldn't directly recommend that) while Collectionsjust provides useful operations for handling the collections.

在我看来,主要区别在于它Collection是基本接口,您可以在代码中将其用作对象类型(尽管我不会直接推荐),同时Collections仅提供用于处理集合的有用操作。

回答by jai

collection: A collection(with small 'c') represents a group of objects/elements.

集合:集合(带有小“c”)表示一组对象/元素。

Collection: The root interfaceof Java Collections Framework.

Collection:根接口Java集合框架

Collections: A utility class that is a member of the Java Collections Framework.

Collections:一个实用程序类,它是Java 集合框架的成员 。

回答by Srinivas

Collection, as its javadoc says is "The root interface in the collection hierarchy." This means that every single class implementing Collection in any form is part of the Java Collections Framework.

集合,正如它的 javadoc 所说的是“集合层次结构中的根接口”。这意味着以任何形式实现 Collection 的每个类都是 Java Collections Framework 的一部分。

The Collections Framework is Java's native implementation of data structure classes (with implementation specific properties) which represent a group of objects which are somehow related to each other and thus can be called a collection.

集合框架是 Java 的数据结构类(具有特定于实现的属性)的本地实现,这些类表示一组对象,这些对象以某种方式彼此相关,因此可以称为集合。

Collections is merely an utility method class for doing certain operations, for example adding thread safety to your ArrayList instance by doing this:

Collections 只是用于执行某些操作的实用方法类,例如通过执行以下操作为 ArrayList 实例添加线程安全性:

List list = Collections.synchronizedList(new Arraylist());

列表列表 = Collections.synchronizedList(new Arraylist());

The main difference in my opinion is that Collection is base interface which you may use in your code as a type for object (although I wouldn't directly recommend that) while Collections just provides useful operations for handling the collections.

我认为的主要区别在于 Collection 是基本接口,您可以在代码中将其用作对象类型(尽管我不会直接推荐),而 Collections 仅提供用于处理集合的有用操作。

回答by raju

collection is an interface and it is a root interface for all classes and interfaces like set,list and map.........and all the interfaces can implement collection interface.

collection 是一个接口,它是所有类和接口的根接口,如 set、list 和 map…………所有接口都可以实现集合接口。

Collections is a class that can also implements collection interface.......

Collections 是一个类,也可以实现集合接口......

回答by Mithilesh Kumar Thakur

Collection is a base interface for most collection classes (it is the root interface of java collection framework) Collections is a utility class

Collection 是大多数集合类的基本接口(它是 java 集合框架的根接口) Collections 是一个实用类

Collections class is a utility class having static methods It implements Polymorphic algorithms which operate on collections.

Collections 类是一个具有静态方法的实用类,它实现了对集合进行操作的多态算法。

回答by titas roy

Collections is a class which has some static methods and that method returns the collection. Collection is an interface,rather than root interface in collection hierarchy.

Collections 是一个具有一些静态方法的类,该方法返回集合。集合是一个接口,而不是集合层次结构中的根接口。

回答by kevendra

The Collectionsclass is a utility class having static methods for doing operations on objects of classes which implement the Collectioninterface. For example, Collections has methods for finding the max element in a Collection.

Collections班是具有上实现了这个类的对象做操作的静态方法的实用程序类Collection接口。例如,Collections 有一些方法可以在一个Collection.

回答by srikanth

Collection is an Interface which can used to Represent a Group of Individual object as a single Entity.

集合是一个接口,可用于将一组单个对象表示为单个实体。

Collections is an utility class to Define several Utility Methods for Collection object.

Collections 是一个实用类,用于为 Collection 对象定义多个实用方法。