128_容器_工具类Collections方法详解_洗牌
来源:互联网 发布:淘宝快递模板下载 编辑:程序博客网 时间:2024/06/14 09:09
- TestCollections.java
package collection.sort.collections_detail;import java.util.ArrayList;import java.util.Collections;import java.util.List;/** *1、 binarySearch(List<? extends Comparable<? super T>> list, T key) 容器有序 *2、sort(List<T> list) sort(List<T> list, Comparator<? super T> c) *3、reverse(List<?> list) 4、shuffle(List<?> list) 洗牌 5、swap(List<?> list, int i, int j) */public class TestCollections { //反转 public static void test1(){ List<Integer> list =new ArrayList<Integer>(); list.add(1); list.add(2); list.add(3); list.add(4); System.out.println(list); Collections.reverse(list); System.out.println("反转之后"+list); } public static void main(String[] args) { List<Integer> cards =new ArrayList<Integer>(); //shuffle 洗牌 模拟斗地主 for(int i=0;i<54;i++){ cards.add(i); } //洗牌 Collections.shuffle(cards) ; //依次发牌 List<Integer> p1 =new ArrayList<Integer>(); List<Integer> p2 =new ArrayList<Integer>(); List<Integer> p3 =new ArrayList<Integer>(); List<Integer> last =new ArrayList<Integer>(); for(int i=0;i<51;i+=3){ p1.add(cards.get(i)); p2.add(cards.get(i+1)); p3.add(cards.get(i+2)); } //最后三张为底牌 last.add(cards.get(51)); last.add(cards.get(52)); last.add(cards.get(53)); System.out.println("第一个人:"+p1); System.out.println("第二个人:"+p2); System.out.println("第三个人:"+p3); System.out.println("底牌为:"+last); System.out.println("==========================="); test1(); } }
阅读全文
0 0
- 128_容器_工具类Collections方法详解_洗牌
- Java类集 _集合工具类:Collections
- Java类集 _集合工具类:Collections
- Java类集 _集合工具类:Collections
- 100_容器_List_ArrayList_LinkedList_Vector用法_详解
- 程序设计_洗牌程序
- 黑马程序员_集合框架,泛型,Collections工具类
- 124_容器_内置类比较_Comparable_排序工具类实现
- 125_容器_内置类比较_Comparator_排序工具类实现
- 黑马程序员_泛型、Collections类
- java基础知识_容器类
- 116_容器_自定义泛型_泛型类_泛型接口_泛型方法_安全_省心
- 117_容器_自定义泛型_深入1_子类_属性类型_重写方法类型_泛型擦除
- ^_^
- ^_^
- ^_^
- ^_^
- *_&
- 127_容器_排序容器_TreeSet与TreeMap
- 关于JSON与ajax操作
- PHP后台支付的开发:微信支付和支付宝支付
- web components简介
- Linux基础
- 128_容器_工具类Collections方法详解_洗牌
- C# SQL Server的封装(SQLDataAdapter等)之二(共二)
- Android View绘制和显示原理简介
- Protocol Buffer C++应用实例
- vim和shell脚本基础
- 如何给ArrayList<Integer>对象里面添加字符串?
- C基础知识和基本数据类型
- 暑假集训日记--8.5--搜索
- maven debug