集合collection的实现类List,set以及map
来源:互联网 发布:数字电子网络配线架 编辑:程序博客网 时间:2024/05/29 05:16
昨天斌哥讲了collection集合、他的实现类List、set以及map,还有设计模式的单例模式。
List集合的特点是有序可重合,实现类我用了ArrayList,下面是程序
public void List(){ArrayList list = new ArrayList();list.add("123");list.add("abc");list.add(new JButton());System.out.println(list.size());for(int i = 0;i<list.size();i++){System.out.println(list.get(i));}System.out.println("------------------------");}set集合的特点是无序不重合,实现类我用了Hashset,下面是程序
public void List(){ArrayList list = new ArrayList();list.add("123");list.add("abc");list.add(new JButton());System.out.println(list.size());for(int i = 0;i<list.size();i++){System.out.println(list.get(i));}System.out.println("------------------------");}map集合的特点是一对一,键对数值,有点像x/y函数。。
下面是程序
public void testMap(){Map map = new HashMap();map.put(1, "abc");map.put(2, "123");map.put(3,new JButton());System.out.println(map.size());Set set = map.keySet();Iterator it = set.iterator();while(it.hasNext()){System.out.println(map.get(it.next()));}<pre name="code" class="java">private static Student stu ;public static Student getInstance(){ if(stu == null){stu = new Student();}return stu;}
}他们都是容器,可以放任何的基本数据和对象。
斌哥还花了点时间给我们讲了设计模式:观察者模式:监听器、单例模式:一个类只有一个对象、工厂模式、装饰模式等等。。。
单例模式分饿汉式和懒汉式。
一个是在静态方法中直接创建对象,一个是在私有成员那里创建对象,让外部无法访问,方法体是静态方法,外部可以直接访问。
<pre name="code" class="java"><pre name="code" class="java">private static Student stu ;
public static Student getInstance(){ if(stu == null){
<span style="white-space:pre"></span>stu = new Student();}return stu;}另一种:private static Stduent stu = new Student();
public static Student getInstance(){
return stu ;
}
第一种如果在if条件里面加入了线程和耗时操作就不行了,会有bug。
以上便是昨天上课的总结。下面有collection的实现类的测试图片。加油
2 0
- 集合collection的实现类List,set以及map
- 集合类:Collection--List, Set, Map
- java集合类,collection,list,set,map
- 集合类的使用? collection set map list
- java 集合架构--[Collection] [List] [Set] [Map] [集合工具类]
- java 集合架构--[Collection] [List] [Set] [Map] [集合工具类]
- java 集合架构--[Collection] [List] [Set] [Map] [集合工具类]
- java 的集合。Collection List Set Map 区别
- 各种迷茫的集合。。collection、 list 、set 、map 。。
- java集合类 collection set list map详解
- java中的Collection集合 List Set Map
- java 集合 list map set collection
- 集合框架:Collection、list、set、map:
- java中的Collection集合 List Set Map
- 集合Collection,List,Set,Map,Iterator,Entry
- java集合之Collection---set/map/list
- 集合类(Collection) List/Set/Map... 的区别和联系
- Java基本概念:集合类(Collection)List/Set/Map... 的区别和联系
- 安装AndroidStudio后Eclipse 无法启动问题
- android笔记--保存和恢复activity的状态数据
- CString之GetBuffer
- android NDK开发编译时出现Type 'jint' could not be resolved和Unresolved inclusion: <jni.h>的解决办法
- OC_02
- 集合collection的实现类List,set以及map
- object-c图形绘制总结
- 指针学习注意点
- 【转载整理】Android对话框
- Django+Jquery+Bootstrap Modal+Iframe使用异步机制上传文件实现方法
- 《game design workshop》阅读笔记(四)——Game Design Basics——Working with Formal Elements
- MySQL Community Server 5.7 的数据备份
- HelloWorldServlet
- 用例图之包含、扩展、泛化