Test Collections 【006】

xiaoxiao2026-01-14  2

[code] 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,不然结果不确定 } } [/code] _____________________________________________________________________ _____________________________________________________________________ [code] console: [5, 3, 6] [3, 5, 6] [a0, a1, a2, a3, a4] [a4, a0, a3, a2, a1] [a1, a2, a3, a0, a4] 3 [/code]
转载请注明原文地址: https://www.6miu.com/read-5042625.html

最新回复(0)