zoukankan      html  css  js  c++  java
  • Collections

     Collections shuffle   生成随机的序列
    package cn.lijun.demo2;
    
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.List;
    
    public class CollectionsDemo {
        public static void main(String[] args) {
            //fun();
            fun1();
        }
        public static void fun(){
            List<Integer> s=new ArrayList<Integer>();
            s.add(1);
            s.add(2);
            s.add(3344);
            s.add(454);
            s.add(5656);
            System.out.println(s);     //[1, 2, 3344, 454, 5656]
            //调用 工具类方法shuffle 对集合进行随机排列
            Collections.shuffle(s);
            System.out.println(s);      //[454, 2, 1, 3344, 5656]
            
        }
        //Collections.binarysSearch   静态方法  查询集合是否又该元素  有了 返回下标  没有 返回负数
        public static void fun1(){
            List<String> s=new ArrayList<String>();
            s.add("a");
            s.add("b");
            s.add("c");
            s.add("e");
            int i = Collections.binarySearch(s,"a");
            System.out.println(i);
           
        }
    
    }
  • 相关阅读:
    POJ
    POJ
    操作系统
    POJ
    POJ
    codeforces Educational Round 89
    codeforces Round 647(div. 2)
    codeforces Educational Round 88
    后缀自动机简单总结
    dsu on tree 简单总结
  • 原文地址:https://www.cnblogs.com/qurui1998/p/10580776.html
Copyright © 2011-2022 走看看