一、集合框架(Collection和Collections的区别)
一、Collection和Map
是一个接口
Collection是Set,List,Queue,Deque的接口
Set:无序集合,List:链表,Queue:先进先出队列,Deque:双向链表
Collection和Map之间没有关系,Collection里放一个一个对象的,Map是放键值对key-value。

二、Collections
Collections是一个类,也就是容器的工具类,如同Arrays就是数组的工具类
里面有很多方法:
常用的:reverse():反转,逆序
shuffle():混淆,就跟洗牌一样,随机打乱顺序
sort():排序从小到大的顺序
swap():交换
rotate():向右滚动
package collection;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List; public class TestCollection{
public static void main(String[] args){
//初始化集合
List<Integer> num=new ArrayList<Integer>();
for(int i=0;i<10;i++){
num.add(i);
}
System.out.println("集合中的数据:");
System.out.println(num);//0 1 2 3 4 5 6 7 8 9
Collections.reverse(num);
System.out.println("翻转后集合中的数据:");
System.out.println(num);//9 8 7 6 5 4 3 2 1 0
Collections.shuffle(num);
System.out.println("混淆后集合中的数据:");
System.out.println(num);//7 5 4 1 2 6 9 3 0 8
Collections.sort(num);
System.out.println("排序后集合中的数据:");
System.out.println(num);//0 1 2 3 4 5 6 7 8 9
Collections.swap(num,0,6);
System.out.println("交换0和6位置的数据后,集合的数据为:");
System.out.println(num);//6 1 2 3 4 5 0 7 8 9
Collections.rotate(num,2);//向右滚动
System.out.println("把集合向右滚动2个单位,集合中的数据为");//也就是把集合中最后面的两个数,放到最前面来。其余不变。
System.out.println(num);//8 9 6 1 2 3 4 5 0
}
}
synchronizedList():线程安全化
也就是把不安全线程转化为安全线程,比如ArrayList是不安全线程,在多线程中不能用,而Vector是多线程的安全。
package collection;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List; public class TestCollection{
public static void main(String[] args){
List<Integer> num=new ArrayList<Integer>();
System.out.println("把非安全线程的List转换为线程安全的List");
Collections.synchronizedList(num);
}
}
一、集合框架(Collection和Collections的区别)的更多相关文章
- 介绍Collection框架的结构;Collection 和 Collections的区别
介绍Collection框架的结构:Collection 和 Collections的区别 集合框架: Collection:List列表,Set集 Map:Hashtable,HashMap,Tre ...
- Java学习笔记--Collection和Collections的区别
转自 http://pengcqu.iteye.com/blog/492196 比较Collection 和Collections的区别. 1.java.util.Collection 是一个集合 ...
- Java集合框架Collection
转自:http://www.cdtarena.com/javapx/201306/8891.html [plain] view plaincopyprint?01.在 Java2中,有一套设计优良的接 ...
- 浅谈集合框架五——集合框架扩展:Collections工具类的使用,自定义比较器
最近刚学完集合框架,想把自己的一些学习笔记与想法整理一下,所以本篇博客或许会有一些内容写的不严谨或者不正确,还请大神指出.初学者对于本篇博客只建议作为参考,欢迎留言共同学习. 之前有介绍集合框架的体系 ...
- Collection 和 Collections的区别。
Collection 和 Collections的区别. Collections是个java.util下的类,它包含有各种有关集合操作的静态方法. Collection是个java.util下的接口, ...
- Collection 和 Collections的区别。(转)
Collection 和 Collections的区别. Collections是个java.util下的类,它包含有各种有关集合操作的静态方法. Collection是个java.util下的接口, ...
- HashMap和Hashtable的区别--List,Set,Map等接口是否都继承自Map接口--Collection和Collections的区别
面试题: 1.HashMap和Hashtable的区别? HashMap:线程不安全,效率高,键和值都允许null值 Hashtable:线程安全,效率低,键和值都不允许null值 ArrayList ...
- Java中的集合框架-Collection(二)
上一篇<Java中的集合框架-Collection(一)>把Java集合框架中的Collection与List及其常用实现类的功能大致记录了一下,本篇接着记录Collection的另一个子 ...
- Collection 和 Collections的区别?
Collection 和 Collections的区别? 解答:Collection是java.util下的接口,它是各种集合的父接口,继承于它的接口主要有Set 和List:Collections是 ...
- 理解java集合——集合框架 Collection、Map
1.概述: @white Java集合就像一种容器,可以把多个对象(实际上是对象的引用,但习惯上都称对象)"丢进"该容器中. 2.Java集合大致可以分4类: @white Set ...
随机推荐
- 1、Ansible简介及简单安装、使用
参考Ansible权威指南:https://ansible-tran.readthedocs.io/en/latest/index.html 以下内容学习自马哥教育 Ansible: 运维工作:系统安 ...
- python学习打卡 day07 set集合,深浅拷贝以及部分知识点补充
本节的主要内容: 基础数据类型补充 set集合 深浅拷贝 主要内容: 一.基础数据类型补充 字符串: li = ["李嘉诚", "麻花藤", "⻩海峰 ...
- MInio python
# Install Minio library. # $ pip install minio # # Import Minio library. from minio import Minio # I ...
- vue运行报错--dependency
ERROR Failed to compile with 1 errors 11:17:27 This dependency was not found: 解决方法:把报错所缺少的依赖都装上 如 xx ...
- _spellmod_aura_trigger
一.spell.dbc做一个空光环 二.配置_spellmod_aura_trigger表 comment 备注 aura 光环ID,有此光环时,才会触发下面技能 linkSpell1-3 链接的技能 ...
- AndroidImageSlider第一张图闪过的问题解决
1. AndroidImageSlider的使用: 参考源码:https://github.com/daimajia/AndroidImageSlider 当然网上介绍使用方法的很多,搜一搜. 2. ...
- Jmeter 接口测试知识梳理——环境搭建篇
Jmeter 使用也有很长时间了,但是一直没有做一下知识梳理,近期会对公司同事做一下这方面的培训,借此机会,把使用过程中应用到的知识,或是遇到的问题,整理出来,方便大家学习! 环境搭建篇 很多文章介绍 ...
- python中的面向对象学习以及类的封装(这篇文章初学者一定要好好看)
这篇文章对于初学者可以很有效的理解面对过程.面对对象 一.首先介绍一下面向过程和面向对象的比较: 面向过程 VS 面向对象 编程范式 编程是程序员用特定的语法+数据结构+算法组成的代码来告诉计算机如何 ...
- SQL中的where条件,在数据库中提取与应用浅析
1. 问题描述 一条SQL,在数据库中是如何执行的呢?相信很多人都会对这个问题比较感兴趣.当然,要完整描述一条SQL在数据库中的生命周期,这是一个非常巨大的问题,涵盖了SQL的词法解析.语法解析.权限 ...
- Very Good Article on How Git Commands Work
http://stackoverflow.com/questions/30038999/differences-between-commit-commit-and-push-commit-and-sy ...