Java中的集合
来源:互联网 发布:分布式更新数据 编辑:程序博客网 时间:2024/06/05 05:40
1.javaz集合主要由两个接口派生:Collection和Map。其Collection继承树如下:
Map的继承树为:
其中,粗线圈出的为接口,深黑色背景的为常用的实现类。
2.操作集合的工具类
import java.util.*;class CollectionToolTest {public static void main(String[] args) {ArrayList nums=new ArrayList();nums.add(2);nums.add(-3);nums.add(5);nums.add(0);//排序操作//依顺序进行输出System.out.println(nums);//将元素翻转Collections.reverse(nums);System.out.println(nums);//从小到大进行排序Collections.sort(nums);System.out.println(nums);//随机排序Collections.shuffle(nums);System.out.println(nums);//查找替换操作//返回最大、小值System.out.println(Collections.max(nums));System.out.println(Collections.min(nums));//将其中的0改为1Collections.replaceAll(nums,0,1);System.out.println(nums);//计算-3出现的次数System.out.println(Collections.frequency(nums,-3));//排序并使用二分查找来查找2的索引号Collections.sort(nums);System.out.println(Collections.binarySearch(nums,2));//同步控制Collection c=Collections.synchronizedCollection(new ArrayList());List list=Collections.synchronizedList(new ArrayList());Set s=Collections.synchronizedSet(new HashSet());//设置不可变的集合List unmodList=Collections.emptyList();//创建一个只有一个元素的不可变Set集合Set unmodSet=Collections.singleton("123"); //使用普通的Map对象创建其不可变的版本Map scores=new HashMap();scores.put("zhang1",123);scores.put("zhang2",234);Map unmodMap=Collections.unmodifiableMap(scores);}}
0 0
- JAVA中的集合类
- JAVA中的集合类
- JAVA中的集合类
- JAVA中的集合类
- JAVA中的集合类
- JAVA中的集合类 - -
- JAVA中的集合类
- java中的集合类
- Java中的集合类
- Java中的集合
- JAVA中的集合
- java中的集合
- java中的集合排序
- Java中的一些集合
- JAVA中的集合类
- Java中的集合类
- Java中的集合类
- java中的集合SetEntry
- 简要介绍分布式服务器系统的内部结构
- 对DSP中unsigned long的发现以及对各种变量类型的总结
- EXT复合表头谷歌浏览器Chrome错位解决办法
- memcached实现分布式数据存储
- VS2012配置QT5环境
- Java中的集合
- 我要我们一直在一起
- 让UITableView响应touch事件
- Memcached 集群架构方面的问题
- matlab读取写入图像数据格式uint8,double
- MPlayer
- JQuery事件
- 查看Oracle数据库中未绑定变量的SQL
- 拷贝构造函数