Collection: Effectuer une recherche binaire dans une ‘ArrayList’

Author:

 list, list, arrayList, collection, collection, arrayList, java
Download

import java.util.ArrayList;
import java.util.Collections;
 
public class ArrayL_BinSearch
 {
 
  public static void main(String[] args)
  	{
 
    ArrayList<String> array_L = new ArrayList();
 
    array_L.add("Java");
    array_L.add("Perl");
    array_L.add("PHP");
    array_L.add("CSharp");
    array_L.add("C++");
 
    // Le tri est obligatoire avant la recherche binaire
    Collections.sort(array_L);
 
    System.out.println("Contenu Trié : " + array_L);
 
    // Trouver python dans la collection
    int index = Collections.binarySearch(array_L, "Python");
    System.out.println("Index de python = " + index);  // "-N"
  }
}