Mega Code Archive

 
Categories / Java / Collections Data Structure
 

If the element is a primitive type

import java.util.Arrays; public class Main {   public static void main(String[] argv) throws Exception {     // Create an array with an ordered list of numbers     int[] sortedIntArray = new int[] { 1, 2, 3, 5, 7 };     // Search for 6     int index = Arrays.binarySearch(sortedIntArray, 6);     System.out.println(index);   } }