Collections
2015-12-08 22:01
399 查看
/* * file name: CollectionsTest.java * copyright: Unis Cloud Information Technology Co., Ltd. Copyright 2015, All rights reserved * description: <description> * mofidy staff: zheng * mofidy time: 2015年12月6日 */ package com.utils.test; import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import java.util.List; /** * <Simple feature description > * <Detailed feature description> * * @author zheng * @version [version, 2015年12月6日] * @see [about class/method] * @since [product/module version] */ public class CollectionsTest { public static void main(String[] args) { Integer[] array = {1,6,23,45,88,99}; Integer[] arr = {13,1,6,23,45,88,99,11}; List<Integer> list = Arrays.asList(array); List<Integer> copyList = Arrays.asList(arr); //Reverses the order of the elements in the specified list. Collections.reverse(list); //Randomly permutes the specified list using a default source of randomness. All permutations occur with approximately equal likelihood. Collections.shuffle(list); //Swaps the elements at the specified positions in the specified list. Collections.swap(list, 2, 5); //Replaces all of the elements of the specified list with the specified element. Collections.fill(list, null); /** * Copies all of the elements from one list into another.(copy src to dest) After the * operation, the index of each copied element in the destination list * will be identical to its index in the source list. The destination * list must be at least as long as the source list. If it is longer, the * remaining elements in the destination list are unaffected. <p> */ Collections.copy(list, copyList); //Rotates the elements in the specified list by the specified distance. Collections.rotate(list, 1); //Replaces all occurrences of one specified value in a list with another. Collections.replaceAll(list, 1, 77); //Returns the starting position of the first occurrence of the specified //target list within the specified source list, or -1 if there is no such occurrence. int num = Collections.indexOfSubList(copyList,list); int num1 = Collections.lastIndexOfSubList(copyList,list); //Returns an unmodifiable view of the specified list. List<Integer> list2 = Collections.unmodifiableList(list); //Returns a synchronized (thread-safe) list backed by the specified list. List<Integer> list3 = (List<Integer>) Collections.synchronizedList(list); synchronized (list3) { Iterator<Integer> iterator = list3.iterator(); while(iterator.hasNext()){ System.out.print(iterator.next()+" "); } } //Returns {@code true} if the two specified collections have no elements in common. boolean flag = Collections.disjoint(list, copyList); //Adds all of the specified elements to the specified collection. Collections.addAll(list, 44); for(int i=0;i<list.size();i++){ System.out.print(list.get(i)+" "); } } }
相关文章推荐
- android中正确保存view的状态
- 在Visual Studio中开启OpenMP
- VIM+qmake编译示例程序HelloQt出错问题的解决(文件名一定要使用.cpp,否则就会默认使用gcc编译,当然通不过)
- 杭电5532 Almost Sorted Array
- 关联容器(二):mutiset
- Linux-MongoDB安装说明
- 【学习】Javascript设计模式——反模式
- 自定义带下拉刷新和滚动加载的ListView控件原理分析和实现
- Qt中各个widget前后位置的设定(在Qt中,所有问题都要一分为二,QWidget体系和QGraphicsWidget体系)
- 『原创』统计建模与R软件-第二章 R软件的使用
- 矩形(两个矩形覆盖面积)
- 书写一个twisted的Daemon
- Linux命令
- 获得系统状态栏高度和获得资源文件ID
- android Fragment 实现切换卡效果
- Eclipse-----Eclipse使用命令行
- zzulioj 题目1813: good string(水题,要严谨啊)
- 【bzoj1251】序列终结者 Splay
- 学习总结(15-12-8)
- js验证IP及子网掩码的合法性