Java中对List集合内的元素进行顺序、倒序、随机排序的示例代码
import java.util.Collections; import java.util.LinkedList; import java.util.List; public class Test { List list = new LinkedList(); public static void main(String[] args) { List list = new LinkedList(); for ( int i = 0 ; i < 9 ; i ++ ) { list.add( " a " + i); } Collections.sort(list); // 顺序排列 System.out.println(list); Collections.shuffle(list); // 混乱的意思 System.out.println(list); Collections.reverse(list); // 倒序排列 System.out.println(list); System.out.println(Collections.binarySearch(list, " a5 " )); // 折半查找 } }