The program sorts the array from lowest to highest and outputs the index of the searched value:public static void main(String[] args) {    Integer[] random = {6, -4, 12, 0, -10};    List<Integer> list = new ArrayList<Integer>(Arrays.asList(random));    Collections.sort(list);    Integer[] array = list.toArray(new Integer[list.size()]);    int y = Arrays.binarySearch(array, 6);    System.out.println(y);}This works as expected, but you can see that I had to use 3 lines just to sort the array, before being able to do a binarySearch on it.Can this code be improved?
Sorting an Integer array
java;array;sorting;binary search
As you say, this is wrong. ThisInteger[] random = {6, -4, 12, 0, -10};List<Integer> list = new ArrayList<Integer>(Arrays.asList(random));Collections.sort(list);Integer[] array = list.toArray(new Integer[list.size()]);could be replaced byInteger[] random = {6, -4, 12, 0, -10};List<Integer> list = Arrays.asList(random);Collections.sort(random);where Arrays.asList just wraps the array without making a copy. Even better would beInteger[] random = {6, -4, 12, 0, -10};Arrays.sort(random);Also note that sorting something just in order to be able to use binary search once makes no sense.Also note thatInteger[] random = {6, -4, 12, 0, -10};uses objects wrapping the int, whileint[] random = {6, -4, 12, 0, -10};would be much more efficient.