List、Collections
来源:互联网 发布:阿里云校园招聘 编辑:程序博客网 时间:2024/06/06 11:36
java.util.Collections提供了一些有关List操作的静态方法,很有效的对List进行操作
1.sort(List)---对List中的元素排序
2. shuffle(List)----对List中的元素随机排序
3.reverse(List)---对List中的元素反转
。。。。。。。。
import java.util.*;public class TestList {/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubList<String> ls=new LinkedList<String>();for(int i=0;i<=9;i++){ls.add("a"+i);}System.out.println(ls);//随机排列Collections.shuffle(ls);System.out.println(ls);//逆序排列Collections.reverse(ls);System.out.println(ls);//排序Collections.sort(ls);System.out.println(ls);//二分查找System.out.println(Collections.binarySearch(ls, "a2"));//定义一个新的ListList<String> lst=new LinkedList<String>();for(int j=0;j<20;j++){lst.add("b"+j);}System.out.println(lst);Collections.copy(lst, ls);System.out.println(lst);}}//结果(不唯一)为:/*[a0, a1, a2, a3, a4, a5, a6, a7, a8, a9][a4, a3, a6, a8, a1, a9, a7, a0, a2, a5][a5, a2, a0, a7, a9, a1, a8, a6, a3, a4][a0, a1, a2, a3, a4, a5, a6, a7, a8, a9]2[b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19][a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19]*/
- List、Collections
- List接口&&Collections类
- Collections.synchronizedList(list)
- Collections 对List排序
- Collections排序List<Map>
- 列式出 List / Map / Collections
- List / Map / Collections方法
- List / Map / Collections
- List / Map / Collections
- List / Map / Collections方法
- List / Map / Collections方法
- List Map Collections
- List / Map / Collections方法
- List / Map / Collections
- List / Map / Collections
- list排序(Collections.sort())
- Collections.sort() 对 List 排序
- Collections.sort() 对 List 排序
- RMAN常用的命令
- 系统还原 和 System Volume Information 文件夹
- Oracle冷备份
- PicoContainer学习手册
- mysql中data too long for column问题的解决方法
- List、Collections
- Oracle控制文件详解
- Linux下svn命令大全
- DirectSound问题
- Linux字符设备驱动程序编写基本流程
- 查看源文件
- Softs Update
- 不当事务代码引起的数据库死锁问题
- Flash Builder 找不到所需的 Adobe Flash Player 调试器版本