package com.testcollecton;
import java.lang.Comparable ;
import java.util.List;
import java.util.LinkedList ;
import java.util.Collections ;
public class TestCollections {
public static void main(String args[]) {
List list = new LinkedList() ;
for(int i=0; i<5; i++) {
list.add("a" + i) ;
}
//listt test Comparable class
List listt = new LinkedList() ;
// for(int j=0; j<8; ) {
// listt.add(j) ;
// j = j+2 ;
// }
listt.add("5") ;
listt.add("3") ;
listt.add("6") ;
System.out.println(listt) ;
Collections.sort(listt) ; //根据元素的自然顺序 对指定列表按升序进行排序
System.out.println(listt) ;
System.out.println(list) ;
Collections.shuffle(list) ; //随机排序
System.out.println(list) ;
Collections.reverse(list) ; //反转指定列表中元素的顺序
System.out.println(list) ;
Collections.sort(list) ;
System.out.println(Collections.binarySearch(list, "a3")) ; //需要先进性sort,不然结果不确定
}
}
_____________________________________________________________________
_____________________________________________________________________
console:
[5, 3, 6]
[3, 5, 6]
[a0, a1, a2, a3, a4]
[a4, a0, a3, a2, a1]
[a1, a2, a3, a0, a4]
3
分享到:
相关推荐
commons-collections-testframework-3.1.jar, commons-collections-testframework-3.2.1.jar, commons-collections-testframework-3.2.jar, commons-collections.jar, commons-collections3-3.2.1.jar, commons-...
Commons-Collections seek to build upon the JDK classes by providing new interfaces, ...Utilities to test or create typical set-theory properties of collections such as union, intersection, and closure
commons-test
jar包,官方版本,自测可用
实测可用
实测可用
实测可用
实测可用
实测可用
实测可用
实测可用
实测可用
实测可用
实测可用
Apache Commons Collections是一个功能强大的Java库,它扩展了Java的集合框架,提供了许多新的集合类型以及对原有集合类功能的增强。它是为了满足在项目开发过程中,对集合操作的额外需求而设计的。这个库能够使...
官方版本,亲测可用
语义 Web 服务测试集 该项目包含用于测试语义 Web 服务技术的共享资源。 这些测试资源是由许多研究... docker run -d -p 8000:80 openuniversity/sws-test-collections 这将自动从 Docker 中心获取容器并启动它。 一旦
Collections.sort(names, (s1, s2) -> s1.compareTo(s2)); ``` 这里,`(s1, s2) -> s1.compareTo(s2)` 就是一个Lambda表达式,它代表了一个接受两个参数并返回它们比较结果的函数。 #### 流(Streams) Stream API是...
- **Collections**:工具类,提供了一些静态方法来操作集合,如排序、搜索等。 ### 8. 关键字 final, finally, finalize 的用法 - **final**:修饰变量时,表示该变量的值不可更改;修饰方法时,表示该方法不能...
Spring数据mongodb测试 在Collections.synchronizedList或Collections.synchronizedSet上测试spring数据mongodb ConcurrentModificationException