提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
在ArrayList上执行二进制搜索
import java.util.ArrayList;//from 时代Java - N o w J a v a . c o m import java.util.Collections; public class Main { public static void main(String[] args) { ArrayList arrayList = new ArrayList(); arrayList.add("1"); arrayList.add("4"); arrayList.add("2"); arrayList.add("5"); arrayList.add("3"); Collections.sort(arrayList);//来自 n o w j a v a . c o m - 时 代 Java System.out.println("Sorted ArrayList contains : " + arrayList); //search an element using binarySearch method of Collections class