当前位置:  技术问答>C#关于System.Collections空间详解 iis7站长之家

Collections集合的排序问题致疑:

    来源: 互联网  发布时间:2015-05-18

    本文导语:  1、Collections.binarySearch(List,Object)方法返回的int是什么意思,此方法让我有点摸不着关脑; 2、Collections.shuffle(List)和Collections.reverse(List)分别代表升序倒序,但我测试时,每次都得到不同的结果 ,Why?代码如下:      ...

1、Collections.binarySearch(List,Object)方法返回的int是什么意思,此方法让我有点摸不着关脑;

2、Collections.shuffle(List)和Collections.reverse(List)分别代表升序倒序,但我测试时,每次都得到不同的结果 ,Why?代码如下:
        List list=new ArrayList();
        list.add("d");
        list.add("a");
        list.add("f");
        list.add("g");
        //Collections.sort(list);
        Collections.shuffle(list);//顺序,从小到大
        //Collections.reverse(list);//逆序,从大到小
        Iterator iter=list.iterator();
        while(iter.hasNext())
            System.out.println(iter.next());

|
下面是一段关于Collections.binarySearch(List,Object)的API文档,你可以看看!希望对你又用!

binarySearch
public static int binarySearch(List list,
                               Object key)Searches the specified list for the specified object using the binary search algorithm. The list must be sorted into ascending order according to the natural ordering of its elements (as by the sort(List) method, above) prior to making this call. If it is not sorted, the results are undefined. If the list contains multiple elements equal to the specified object, there is no guarantee which one will be found.
This method runs in log(n) time for a "random access" list (which provides near-constant-time positional access). It may run in n log(n) time if it is called on a "sequential access" list (which provides linear-time positional access).

If the specified list implements the AbstracSequentialList interface, this method will do a sequential search instead of a binary search; this offers linear performance instead of n log(n) performance if this method is called on a LinkedList object.
Parameters:
list - the list to be searched.
key - the key to be searched for.
Returns:
index of the search key, if it is contained in the list; otherwise, (-(insertion point) - 1). The insertion point is defined as the point at which the key would be inserted into the list: the index of the first element greater than the key, or list.size(), if all elements in the list are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.
Throws:
ClassCastException - if the list contains elements that are not mutually comparable (for example, strings and integers), or the search key in not mutually comparable with the elements of the list.

    
 
 
 
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。












  • 相关文章推荐
  • java命名空间java.util类collections的类成员方法: emptylist定义及介绍
  • Google Collections
  • java命名空间java.util类collections的类成员方法: emptymap定义及介绍
  • Commons-collections
  • java命名空间java.util类collections的类成员方法: empty_list定义及介绍
  • C#关于System.Collections空间详解
  • java命名空间java.util类collections的类成员方法: empty_set定义及介绍
  • Immutable Collections for Java
  • java命名空间java.util类collections的类成员方法: reverse定义及介绍
  • 这句话Collections is a class, Collection is an interface怎么理解?
  • java命名空间java.util类collections的类成员方法: singleton定义及介绍
  • Python collections模块实例讲解
  • java命名空间java.util类collections的类成员方法: emptyset定义及介绍
  • java命名空间java.util类collections的类成员方法: singletonlist定义及介绍
  • java命名空间java.util类collections的类成员方法: reverseorder定义及介绍
  • java命名空间java.util类collections的类成员方法: enumeration定义及介绍
  • java命名空间java.util类collections的类成员方法: synchronizedlist定义及介绍
  • java命名空间java.util类collections的类成员方法: fill定义及介绍
  • java命名空间java.util类collections的类成员方法: synchronizedset定义及介绍
  • java命名空间java.util类collections的类成员方法: singletonmap定义及介绍
  • java命名空间java.util类collections的类成员方法: list定义及介绍


  • 站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,,E-mail:www_#163.com(请将#改为@)

    浙ICP备11055608号-3