【面试题】Collection包结构,与Collections的区别

java面试题48 Collection 和 Collections 的区别? 对比维度Collection定位集合的抽象规范操作集合的工具箱是否继承是(List/Set/Queue 的父接口)否(final 类,不可继承)线程安全大部分实现非线程安全提供线程安全包装方法数据修改定义数据操作规范(如 add/remove)提供算法操作(如 sort/shuffle)设计模式接口(规范行为)工具类(实用主义)Collection是集合的“宪法”(定义规则)是集合的“瑞士军刀”(提供工具)。理解这个区别能避免在代码中出现这类错误,同时掌握的工具方法可极大提升开发效率!🛠️。 阅读详情

理论认知

在Java中,Collection 是一个接口,位于 java.util 包中,它定义了一系列操作单列集合(例如,List、Set 和 Queue)的方法。Collection 接口是 List、Set 和 Queue 接口的父接口,但它不提供具体的实现。这些接口的实现类(如 ArrayList、HashSet、LinkedList 等)提供了具体的集合存储和操作方法。

另一方面,Collections 是一个工具类(而非接口),也位于 java.util 包中。Collections 类提供了许多静态方法,用于操作或返回集合的视图,例如排序、搜索、线程安全、不可变等。这些静态方法允许你对集合进行各种操作,而无需修改集合类本身。

以下是它们之间的一些主要区别:

  1. 类型:

    • Collection 是一个接口。
    • Collections 是一个工具类。
  2. 目的:

    • Collection 接口定义了单列集合的通用操作,如添加、删除、检查元素是否存在、迭代等。
    • Collections 类提供了对集合进行操作的静态方法,这些方法通常不需要修改集合类本身。
  3. 实现:

    • Collection 接口没有具体的实现,而是由其子接口(如 List、Set)和它们的实现类(如 ArrayList、HashSet)来实现。
    • Collections 类提供了许多静态方法,这些方法可以直接使用,无需创建 Collections 类的实例。
  4. 方法:

    • Collection 接口定义了如 add、remove、contains、size 等方法。
    • Collections 类提供了如 sort、binarySearch、synchronizedList、emptyList 等静态方法。
  5. 使用:

    • 当你需要创建一个集合并使用其通用方法时,你会实现或实例化一个 Collection 接口的子接口(如 List 或 Set)的实现类。
    • 当你需要对集合进行排序、搜索、线程安全处理或其他高级操作时,你会使用 Collections 类中的静态方法。
  6. 线程安全:

    • Collection 接口及其实现类(如 ArrayList、HashSet)默认不是线程安全的。
    • Collections 类提供了一些线程安全的静态方法,如 synchronizedList,可以将一个非线程安全的列表转换为线程安全的列表。

总之,Collection 是Java集合框架中的一个核心接口,而 Collections 是一个为集合提供操作方法的工具类。它们各自在集合框架中扮演着不同的角色。

以下是Collection接口和Collections工具类的代码示例:

使用Collection接口(例如ArrayList)

下滑查看解决方法

import java.util.ArrayList;
import java.util.Collection;

public class CollectionExample {
    public static void main(String[] args) {
        // 创建一个ArrayList实例,它实现了Collection接口
        Collection<String> collection = new ArrayList<>();

        // 添加元素到集合中
        collection.add("One");
        collection.add("Two");
        collection.add("Three");

        // 检查元素是否存在
        boolean containsTwo = collection.contains("Two");
        System.out.println("Contains 'Two'? " + containsTwo);

        // 遍历集合
        for (String element : collection) {
            System.out.println(element);
        }

        // 删除元素
        collection.remove("Two");

        // 再次遍历集合以确认元素已被删除
        for (String element : collection) {
            System.out.println(element);
        }
    }
}

使用Collections工具类

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class CollectionsExample {
    public static void main(String[] args) {
        // 创建一个ArrayList实例
        List<String> list = new ArrayList<>();

        // 添加元素到列表中
        list.add("Apple");
        list.add("Banana");
        list.add("Cherry");

        // 使用Collections工具类对列表进行排序(假设列表中的元素实现了Comparable接口)
        Collections.sort(list);

        // 遍历排序后的列表
        for (String fruit : list) {
            System.out.println(fruit);
        }

        // 使用Collections工具类查找元素(注意这里使用的是binarySearch,它要求列表已排序)
        int index = Collections.binarySearch(list, "Banana");
        System.out.println("Index of 'Banana': " + index);

        // 使用Collections工具类创建一个线程安全的列表
        List<String> synchronizedList = Collections.synchronizedList(new ArrayList<>());

        // 注意:尽管列表本身是线程安全的,但迭代时仍需要额外的同步
        // ...(此处省略了同步迭代的代码)

        // 使用Collections工具类创建一个不可修改的列表
        List<String> unmodifiableList = Collections.unmodifiableList(list);

        // 尝试修改unmodifiableList将会抛出UnsupportedOperationException
        // unmodifiableList.add("Date"); // 这行代码将会抛出异常
    }
}

这些示例展示了Collection接口和Collections工具类在Java集合框架中的基本用法。Collection接口定义了集合的基本操作,而Collections工具类提供了对集合进行排序、搜索和修改等操作的静态方法。

Java大厂面试高频:Collection 和 Collections 到底咋回答? 为了让小王彻底吃透,我举了个生活中的例子:“Collection 就像是一张空白的表格(比如清单或队列),定义了你能往表格里加什么、怎么加;而 Collections 就像是操作这张表格的工具(比如排序器、查找器),让你轻松完成一些常见的表格操作。小王恍然大悟:“原来是这么回事! 阅读详情

相关推荐

使用.NET 免费开源包ViewFaceCore做一个人脸识别并注册的功能,没有比我更全的

本文介绍了一个基于WinForm的免费人脸识别系统实现方案。系统使用AForge和ViewFaceCore库,支持从USB或电脑自带摄像头采集图像,具备人脸注册和快速识别功能。硬件方面仅需普通摄像头,软件依赖多个NuGet包(如AForge.Video、ViewFaceCore等)。界面包含视频显示、图像预览和功能按钮控件,后台采用SQLServer存储用户面部特征数据。核心代码展示了人脸检测、特征提取和多线程处理逻辑,通过ViewFaceCore实现高效识别。系统具有识别速度快、准确率高的特点,适合Win

一个靠“吃代码”长大的程序猿,专治各种“Bug 饥饿症”。 817

【Java面试题】31 介绍Collection框架的结构

Collection:List列表,Set集 Map:Hashtable,HashMap,TreeMap   Collection  是单列集合 List   元素是有序的、可重复 有序的 collection,可以对列表中每个元素的插入位置进行精确地控制。 可以根据元素的整数索引(在列表中的位置)访问元素,并搜索列表中的元素。  可存放重复元素,元素存取是有序的。 List接口中常用类 l Ve...

weixin_34087307的博客 643

告别Visual Studio!用MSYS2+GCC+CMake在Windows上打造Linux式C++开发环境(保姆级避坑)

本文详细介绍了如何在Windows上使用MSYS2+GCC+CMake搭建Linux式C++开发环境,替代Visual Studio。从MSYS2的安装配置、MinGW-w64 GCC工具链的部署,到CMake项目的创建与构建,提供了保姆级教程和常见问题解决方案,帮助开发者高效过渡到命令行开发模式。

weixin_30298497的博客 324

Collection包结构,与Collections的区别

List是Collection的一个子接口,它提供了一种有序的集合类型,可以按顺序访问集合中的元素。总的来说,Collection是一个接口,定义了所有集合类的通用方法,而Collections是一个工具类,提供了对集合类的静态工具方法。Collection主要用于实现自定义的集合类或使用集合类中的元素,而Collections主要用于对已有的集合类对象进行操作和优化。Collection接口的主要职责是提供一个方法来获取集合中的元素数量,以及一个用于添加、删除和查找元素的方法。

qq_33240556的博客 518

车辆TBOX科普 第7次 TBOX技术深度解析:硬件架构与核心组件详解

摘要: TBOX(车载远程信息处理单元)是智能网联汽车的核心组件,承担数据采集、通信连接与安全交互等关键功能。其硬件架构以主控单元为核心,采用ARM架构处理器(如NXP i.MX系列)实现高效能低功耗处理,搭配DDR4/LPDDR5内存保障性能,eMMC/UFS存储确保数据可靠性。设计中需平衡车规级可靠性(AEC-Q100)、EMC兼容性及成本控制,同时集成通信、定位与安全模块。未来趋势聚焦异构计算、先进制程及功能安全(ASIL-D)与信息安全融合,推动TBOX向边缘计算节点演进。该技术是汽车智能化转型的重

IT深耕十余载,大道之简 857

基于深度学习的时间序列预测

深度学习在时间序列数据中应用广泛,学术界已经有很多深度学习模型来适应不同领域的时间序列数据集的多样性。那么到底有哪些基于深度学习的时间序列预测模型?他们的优缺点是什么?让我们一起来看一下。

Sharon0408的博客 6580

Python collections 模块介绍

1.简介 collections 是 python 的内置模块,提供了很多方便且高性能的关于集合的操作,掌握这些知识有助于提高代码的性能和可读性。 2.常用功能 2.1 namedtuple 功能详解 namedtuple() 返回一个新的元组子类,且规定了元组的元素的个数,同时除了使用下标获取元素之外,还可以通过属性直接获取。 from collections import namedtuple...

weixin_43632687的博客 1932

KTransformers安装笔记 利用docker安装KTransformers

KTransformers安装笔记 利用docker安装KTransformers

guoqingru0311的博客 1559

python | Collections 包的几个常见用法

简介 之前都没很在意过collections这个模块,以为有很多复杂的功能,所以只考虑了defaultdict一个用法。没想到今天做力扣的时候,看官方解答中Counter也是属于collections模块,这么看这个还是很不错的。 写个总结,以备以后快速检索。 PS:发现这个博客写的很详细啊,有不懂的可以去看看:Python常用数据结构之collections模块 总结 Counter 从名称就能看出来,Counter是计数器,可以对字符串,列表,字典实现计数功能。 示例程序: from collectio

lovetaozibaby的博客 917

用户存续期价值评估CLV(二) BG/NBD Model python模拟

BG/NBD Model …继续 想象每一个客户有两个硬币,一个“Buy Coin"控制客户购买的概率;一个"Die Coin"控制客户流失、不再购买的概率。 前面假设了客户的交易次数服从泊松过程: 在一年中的每个月,客户都以抛硬币的方式来决定是否购买。我们所观察到的购买次数取决与泊松分布的参数 ????。 %matplotlib inline import numpy as np impor...

weixin_43171270的博客 3419

python制作图形化小游戏_创意编程|Python的GUI简易界面设计测测你的反应力

Python的GUI简易界面设计案例测测你的反应力作为初次接触代码编程的你,是不是觉得Python程序除了“码”就是“字”即使是有趣的程序除了烧烧自己的脑,也吸引不到更多人的兴趣,用户体验值接近于0?那你可冤枉了Python,他可是人工智能界的编程语言大咖。今天这个游戏设计就先带领大家,简单体验一下,如何让Python程序图形化。一起来吧!设计我们的小游戏游戏设计思路:电脑随机出...

weixin_34214135的博客 1871

每日一道Java 基础面试题 — Collection包结构,与Collections的区别

1、Collection是集合类的顶级接口 子接口有 Set、List、LinkedList、ArrayList、Vector、Stack、Set; 2、Collections是集合类的一个帮助类 它包含有各种有关集合操作的静态多态方法,用于实现对各种集合的搜索、排序、线程安全化等操作。此类不能实例化,就像一个工具类,服务于Java的Collection框架。 ...

CSNZのBlog 254

173、NPU的编译器开发:开源社区贡献指南

本文分享了在NPU编译器开源社区贡献的经验心得。作者通过实际案例(如卷积维度错误、NaN输出等)阐述了NPU编译器开发的特殊性:硬件迭代快、边界条件复杂、厂商代码不可全信。提出有价值的贡献应聚焦硬件适配测试、性能剖析工具和反模式文档三类内容。强调用实测数据沟通、主动承担维护责任、保持代码通用性等社区协作技巧,并建议通过RFC提前沟通、附硬件实测数据等方式提高PR通过率。最后指出,NPU编译器开发是与聪明人共同填坑的过程,鼓励开发者提交"有诚意的代码"而非完美代码。

m0_50546716的博客 35

Collection 和 Collections 有什么区别?

Collection 和 Collections 有什么区别? Collection是JDK中集合层次结构中的最根本的接口。定义了集合类的基本方法。源码中的解释: * The root interface in the <i>collection hierarchy</i>. A collection * represents a group of obje...

ConstXiong 1万+

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

Java面试题(三)——Collection和Collections的区别

1,区别 Collection,是单列集合的接口,有子接口List和Set Collections,是针对集合操作的工具类,其中包含对集合进行排序和二分查找的方法 2,Collections常用方法 public static &lt;T&gt; void sort (List&lt;T&gt; list):排序,默认情况下是自然排序 public static &lt;T&gt; int...

manduner的博客 6746

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

面试题整理:请说明Collection 和 Collections的区别

请说明Collection 和 Collections的区别

weixin_43698561的博客 1124

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

java collection面试题,【Java面试题】38 Collection 和 Collections的区别

Collection是集合类的一个顶级接口,其直接继承接口有List与Set而Collections则是集合类的一个工具类/帮助类,其中提供了一系列静态方法,用于对集合中元素进行排序、搜索以及线程安全等各种操作。java.util.Collections 是一个包装类。它包含有各种有关集合操作的静态多态方法。此类不能实例化,就像一个工具类,服务于Java的Collection框架。Collecti...

weixin_42151305的博客 315

Java Collection和Collections的区别?,Collections 实现sort排序

面试题, 一、 Collection 1.Collection 是一个 顶级集合是接口(如图) 2.提供所以集合的共性方法 * 一、共性方法: * 1.add(): 添加对象到集合 * 2.remove(E e): 移除对象 * 3.size(): 返回集合个数 * 4.toArray(): 放回集合转化的数组 * 5.isEmpty(): 返回true,集合为空 * 6.contains(E e):

半亩方糖 488

Collection与Collections的区别

经常看到公司的面试题考Collection和Collections的区别。 要回答这个问题,我们首先要对java的容器有一定的了解。java中的容器一共分为两种,一种是存放独立个体,即Collection,一个槽只存放一个对立的对象,另一种是存放键值对象的容器,代表是Map,按照Key-Value存放。 翻看java api 我们可以看到,Collection是一个接口,他的孙子有大家常用的A

u011918260的专栏 1109

Collections中的方法

Collections中的方法 Collections: 面试题:Collection和Collections有什么区别? Collection是集合体系的最顶层,包含了集合体系的共性 Collections是一个工具类,方法都是用于操作Collection 方法: 1.static void swap(List list, int i, int j) :将指定列表中的两个...

云飞扬°的博客 2206

面试题汇总--collection和collections的区别

1、java.util.Collection 是一个集合接口(集合类的一个顶级接口)。 它提供了对集合对象进行基本操作的通用接口方法。 Collection接口在Java 类库中有很多具体的实现。 Collection接口的意义是为各种具体的集合提供了最大化的统一操作方式。 Collection接口的直接继承接口有List与Set。   2、java.util.Collection...

weixin_42078450的博客 270

面试题:Java中Collection与Collections的区别

1、java.util.Collection 是一个集合接口。它提供了对集合对象进行基本操作的通用接口方法。Collection接口在Java 类库中有很多具体的实现。Collection接口的意义是为各种具体的集合提供了最大化的统一操作方式。  Collection   ├List   │├LinkedList   │├ArrayList   │└Vector   │ └S

xiaoyu714543065的专栏 5099

java面试题之collection与collections区别

collection是一个接口接口接口。他抽取出各种集合&lt;继承List和Set&gt;的主要功能,并做出统一行为规范。他是很多集合的祖辈接口,没错父辈接口是List和Set。Collections是一个工具类。工具类是工具,就像Math,Arrays类一样,他是一种工具,集成了很多特定的功能。比如排序,拷贝,替换,反转等等等功能。工具类不能被实例化。 工具类使用方式:类名.方法名()总体来说...

七月七日晴 1951

Java Collection Framework 面试题

以下案例有什么问题?元素自身不具备比较性案例int id;set.add(new Person("马六",25));运行报错。首先,set添加元素的时候,是有比较的,因为它有排序,那么现在添加的是Person对象,对象怎么比较呢?对象不具备比较性(即上面说的元素自身不具备比较性),那么大家注意,对象虽然不具备比较性,对象里面的属性是否具备比较性呢?如果对象的属性具备比较性,让对象(Person)继承Comparable接口,并重写compareTo方法去比较属性是否可以呢?

weixin_46690498的博客 922
上一篇: 【面试题】HashMap和HashTable的认识与却别
下一篇: 【java面试题】java的四种引用,强弱软虚
代码无疆
博客等级 码龄3年 4万+粉丝 305原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值